Math Operation via Embedded Data | Start Date - End Date = ???? | XM Community
Skip to main content

Hi Everyone

Hope you’re well.

Via a subscription cancellation survey, and embedded data I receive.

  • subscription.start_date
  • subscription.end_date

This is captured into data and analysis like this.

  • 2024-01-14
  • 2024-02-13

From the above example, this response had a subscription for 30 days.

How do I save the number 30 into my data and analysis?

Hope you can help.

Thanks 🙂 🤞

One of the approach is to use Data formula task in the workflow. This task will go under response event trigger point. Once we get the days from data formula task, we can use web service task below it to update the response embedded data using update response API.


Hi @Shashi 

Thanks for getting back to me.

Ill look into this, any other easier options? Seems like allot of steps, but if this is the best option let me know.

Have a nice weekend.


HI @Shashi 

Hoping you can help me with what’s next.

I believe I have done the 1st step correctly.

The workflow is…

Thanks :)


Another option is to use JavaScript to calculate a difference in days. Add the fields "subscription.start_date", "subscription.end_date", and "daysDiff" to the top of your SurveyFlow. Then, on the first question in your survey, add the below to the OnReady section of the question's JavaScript:

var date1 = new Date("${e://Field/subscription.start_date}").getTime();
var date2 = new Date("${e://Field/subscription.end_date}").getTime();

var diff = parseInt(date2 - date1);
var days = diff/1000/60/60/24;

Qualtrics.SurveyEngine.setEmbeddedData("daysDiff", days);

I also see the Luxon library recommended for date calculations, but see if the above works for you.


Thanks @Tom_1842 

Do they need to at the top of SurveyFlow? Just I can’t seem to move them up or add new ones at the top.

Thanks :)


The fields need to exist in the Survey Flow before the survey question that contains the JavaScript calculations is displayed. Being unable to edit the Survey Flow doesn't sound right though, you may want to check in with Support.


Ill let you know!

🤞


Amazing @Tom_1842 

It’s working.

Would I do the same to record the difference between….

subscription.free_trial_start_date and subscription.free_trial_end_date

And...

subscription.free_trial_end_date and subscription.start_date

And anyway quick way to calculate this for existing results? 

Thanks :)


Leave a Reply