Dynamic Time Period in QS Calculated Fields

Hello!

I have data with a column indicating period_type (day, week, month and quarter) and a measure field. Based on whether I select Day, Week, Month or Year from a dropdown, I would like the PoP % difference to use these dynamic time periods instead of hardcoded to use either of these.

Thank you!

Hi @Madura_Puri , welcome back to the Community :slight_smile:

You can obtain this, if I understood correctly the issue, by generating different calculated fields based on you Control+Parameter selection.

Let’s say you Parameter, modified when you change the Control dropdown values, is called TimeGranularity. Let’s say also you have a field called MyDate.

You can create calculated fields like this (there are 4 different calculated fields):

PoP_Day = periodOverPeriodDifference(sum(Sales), {MyDate}, "DAY", 1)
PoP_Week = periodOverPeriodDifference(sum(Sales), {MyDate}, "WEEK", 1)
PoP_Month = periodOverPeriodDifference(sum(Sales), {MyDate}, "MONTH", 1)
PoP_Year = periodOverPeriodDifference(sum(Sales), {MyDate}, "YEAR", 1)

Then you can create a final field to be used in your visual, let’s call it PoP:

ifelse(
  ${TimeGranularity} = 'Day', {PoP_Day},
  ${TimeGranularity} = 'Week', {PoP_Week},
  ${TimeGranularity} = 'Month', {PoP_Month},
  ${TimeGranularity} = 'Year', {PoP_Year},
  NULL
)

Now you just have to select this field in your visual, and this should change when you select a different value in the control!

Let me know if this helps :slight_smile:

Andrea

Hi @Madura_Puri

It’s been a while since we last heard from you. If you have any further questions, please let us know how we can assist you.

If we don’t hear back within the next 3 business days, we’ll proceed with close/archive this topic.

Thank you!

Hi @Madura_Puri

Since we have not heard back from you, I’ll go ahead and close/archive this topic. However, if you have any additional questions, feel free to create a new topic in the community and link this discussion for relevant information.

Thank you!