Calculated field | XM Community
Skip to main content

Calculated field

  • November 7, 2022
  • 7 replies
  • 144 views

Forum|alt.badge.img+3
  • Level 1 ●
  • 20 replies

Hello,
I would like to add a field YEAR(TODAY())+4 to my survey. It doesn't need to be visible in the survey, I am more interested in having it pull through into Data & Analysis (export data).

I tried to do this by adding a question and uploading a file with the formula so that the data would show but it doesn't pull through in the export.

Any ideas? Thank you!

7 replies

Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+46
  • 1555 replies
  • November 7, 2022

CLM
You can create an embedded data e.g. Year in survey flow and include this "${date://OtherDate/PT/+4%20year}" as it's value. But it will give you the entire date.
Or for just year value.
You can just create an embedded data called "year" in your survey flow and use the below code in the first question or in the header.
Qualtrics.SurveyEngine.addOnload(function()
{
var d = new Date();
    var year1 = d.getFullYear();
    var month = d.getMonth();
    var day = d.getDate();
    var c = new Date(year1 + 4, month, day);
var year2 = (year1+4);
console.log(year2)
    console.log(c);
Qualtrics.SurveyEngine.setEmbeddedData( 'year', year2 );
});
Hope it helps!


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6083 replies
  • November 7, 2022

CLM,
You can set an embedded data field in the survey flow:
yearPlus4 = ${date://OtherDate/Y/+4 year}


Forum|alt.badge.img+3
  • Author
  • Level 1 ●
  • 20 replies
  • November 7, 2022

Great! thank you...I will try both options and see how it goes.


Forum|alt.badge.img+3
  • Author
  • Level 1 ●
  • 20 replies
  • November 7, 2022

Hello
Tom's code returned a value of 'yearPlus4 = 2026'.

Deepak's code (the short version in embedded data) returned the full date of '7 Nov 2026'.

I am trying to play with the codes to see if I can just get the year to show.


Deepak
QPN Level 8 ●●●●●●●●
Forum|alt.badge.img+46
  • 1555 replies
  • November 7, 2022

https://community.qualtrics.com/XMcommunity/discussion/comment/51869#Comment_51869CLM
You can leave the embedded data empty and just pipe it where required. The JS will auto-fill the embedded data, just include it onload.



TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 6083 replies
  • November 7, 2022

CLM,
I think you misunderstood my comment. It should look like this in the survey flow:
image.png


Forum|alt.badge.img+3
  • Author
  • Level 1 ●
  • 20 replies
  • November 7, 2022

Success! thank you both