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

Math Operation via Embedded Data | Start Date - End Date = ????

  • February 10, 2024
  • 8 replies
  • 372 views

Forum|alt.badge.img+5

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 :) 🤞

8 replies

Shashi
Level 8 ●●●●●●●●
Forum|alt.badge.img+34
  • Level 8 ●●●●●●●●
  • 654 replies
  • February 10, 2024

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.


Forum|alt.badge.img+5
  • Author
  • Level 5 ●●●●●
  • 157 replies
  • February 10, 2024

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.


Forum|alt.badge.img+5
  • Author
  • Level 5 ●●●●●
  • 157 replies
  • February 11, 2024

HI @Shashi 

Hoping you can help me with what’s next.

I believe I have done the 1st step correctly.

The workflow is…

Thanks :)


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • 909 replies
  • February 14, 2024

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.


Forum|alt.badge.img+5
  • Author
  • Level 5 ●●●●●
  • 157 replies
  • February 14, 2024

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 :)


Tom_1842
Level 8 ●●●●●●●●
Forum|alt.badge.img+28
  • Level 8 ●●●●●●●●
  • 909 replies
  • February 14, 2024

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.


Forum|alt.badge.img+5
  • Author
  • Level 5 ●●●●●
  • 157 replies
  • February 14, 2024

Ill let you know!

🤞


Forum|alt.badge.img+5
  • Author
  • Level 5 ●●●●●
  • 157 replies
  • February 14, 2024

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 :)