Calculated field | XM Community
Skip to main content

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!

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!


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


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


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.


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.



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


Success! thank you both


Leave a Reply