How to calculate birth year based on age from a survey question | XM Community
Skip to main content

Hi Qualtrics team,

I have a survey where respondents are directly asked for their age (e.g., via a numeric entry question). I’d like to automatically calculate their year of birth based on the age they provide and store it in an Embedded Data field.

For example, if a respondent enters “30” and the current year is 2025, I’d like the survey to store 1995 as their year of birth.

Could someone guide me on:

  1. How to set up the calculation using Survey Flow and Embedded Data?

  2. Whether I need to use JavaScript within the question, or if this can be done directly via Piped Text and math operations in Qualtrics?

  3. How to ensure the calculation updates automatically depending on the current year?

I think it can be very useful to create gruoups such as Gen Z, Millenials, etc...

Thanks in advance for your help!

 

Hi!

This support page has an overview of setting up math operations.

Although it uses examples from survey questions, the same logic can be used in embedded data fields, set up the Survey Flow. Here is a (slightly more complex) example from a survey of mine

Note that the data field type should be changed to “Number Set”, and that doing this will create a page break between the blocks before and after it in your survey.

You wouldn’t need Javascript if you do it this way, but the year would have to be updated manually in the formula each year in order to adjust for the turn of the calendar.

Hope this helps.

Matt


@VictorAV you can achieve this easily through embedded data. It is a flawed estimate though because you don’t know if someone has turned 30 that year or is 30 and has yet to turn 31. However if you want to assume they are turning X years old in this calendar year than the process will work just fine.

 

Collect age in the survey. Validate that the entry is a number without decimals. Then use the following Survey Flow:

Survey Flow to calculate birth year from age
  • Default block contains your age question
  • CurrentYear uses built in code to extract the year (Y) from today’s current date, making it dynamically update as you wanted  -- use options to set type as number
  • Age pipes in the answer to your age question in the survey  -- use options to set type as number
  • YOB tells the survey to calculate the year of birth by subtracting Age from the Current Year --- options to create a number set for analysis

Here is what the survey looks like. Sorry I can no longer attach .qsf files to give you full access.

 

Survey questions for testing
Age question settings

 


Thanks ​@MatthewM and ​@bstrahin for your feedback! It works!

 


Leave a Reply