is it possible to filter by comparing one embedded data to another? | XM Community
Skip to main content

Hello, there is a situation I have. I have a field where user enters  Order Date in YYYY-mm-dd format.   I save it as embedded data ‘orderDate’.  I want to build a filter where I can see a report for the orders I have for tomorrow. But how do I compare it to tomorrow? (I do have embedded data called tomorrowDate, also in YYYY-mm-dd format) . Can I compare one embedded data to another one? Thank  you. Or may be I can make my orderDate into ‘date’ type somehow?

 

Hi @nonufrie ,

 

You can find date difference and store that value in an embedded data. The value 1 will be the data you require. Say tomorrow is 2023-07-22 and the user entered 2203-07-21 as order date, the difference can be used as a value for your filter.


Yes, you can compare embedded data fields in Qualtrics, but to achieve your goal of filtering orders for tomorrow, it would be better to convert the 'orderDate' embedded data to a 'date' type.

Here's how you can do it:

  1. Convert 'orderDate' to a 'date' type:
  • Go to your Qualtrics survey editor.
  • Click on the "Survey Flow" tab.
  • Add a new "Embedded Data" element.
  • Set the name as 'orderDate_date' (or any other relevant name).
  • In the value field, use the following JavaScript code to convert the 'orderDate' to a 'date' type:

Date.parse("${e://Field/orderDate}")

 

This code will convert the 'orderDate' (which is in the format 'YYYY-mm-dd') to a JavaScript date object.

  1. Calculate 'tomorrowDate':
  • Add another "Embedded Data" element.
  • Set the name as 'tomorrowDate' (or any other relevant name).
  • In the value field, use the following JavaScript code to calculate tomorrow's date:

var today = new Date();
today.setDate(today.getDate() + 1);
var year = today.getFullYear();
var month = today.getMonth() + 1;
if (month < 10) {
  month = "0" + month;
}
var day = today.getDate();
if (day < 10) {
  day = "0" + day;
}
year + "-" + month + "-" + day;


 

This code will calculate tomorrow's date and store it in the 'tomorrowDate' embedded data.

Now, with 'orderDate_date' and 'tomorrowDate' in 'date' format, you can filter your report using the "Date" filter in the Qualtrics report:

  1. Go to the "Reports" section in Qualtrics.
  2. Click on "Create Report."
  3. Choose your data source.
  4. Add a new "Date" filter.
  5. Select 'orderDate_date' as the filter field.
  6. Choose the condition "is" or "is on or after," depending on your reporting needs.
  7. Enter 'tomorrowDate' as the value to compare against.

This filter will now show you a report for orders that have the 'orderDate' equal to or after tomorrow's date.

By converting 'orderDate' and 'tomorrowDate' to 'date' format, you ensure that the comparison is done correctly and avoids any issues with date formatting discrepancies.

 


@Shivamvig_sv when I add Date.parse("${e://Field/orderDate}") into Survey Builder, it just makes it literally Date.parse("${e://Field/orderDate}")  _ I don’t think you can add JS into value?
But what actually worked, was making my original orderDate  embedded data type ‘date’! Thank you for pointing it out! I completely overlooked that ‘option’ link on embedded data survey flow block!

I also have made another Embedded data ‘tomorrow’ and set it as ‘date’ type and assigned it a value of ${date://OtherDate/DS/+1%20day}, which creates Date object in YYYY-MM-DD format. Now I hope I can use @Prateek.Dang suggestion to assign the difference between 2 dates to the third variable. (Have to look up how to do it in Survey Flow, but I think I am on the right track)


I have a problem:( So the user inputs date through the field and it looks like 2023-07-27

I save unto Embedded Data named orderDate (and that data is set to be of type ‘date’). For some reason, qualtrics makes Jul 26, 2023 out of it? 

 


You can check the .qsf in the comments posted by @Tom_1842 

 

How do I subtract between two dates in a survey? | XM Community (qualtrics.com)


@Prateek.Dang I realized your solution wont work, because I can be generating report not necessary the same day as the order was submitted. My ‘today’ would be different from what ‘today’ was when the record was submitted. so diff =1 no longer applies.
So I was hoping that if I set embedded data orderDate  as of type  ‘date’, and than later  do in survey builder 



 If the user has input lets say 2023-07-24, when I look at the end of survey, where I render ${e://Field/orderDate},  it does show ‘2023-07-24’ as expected,
but when I pull orderDate into the report, it becomes ‘Jul 24 2023 8pm EDT’. I don’t mind 8pm EDT, but why is it changing the date? Here’s the screen shot where I pull along the date from Embedded data OrderDate, and from the field itself

 


Leave a Reply