Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
KPage
Contributor III
Contributor III

Create new Date Dimension

Hi,

I would like to create a "Date" dimension that only uses the current year and the prior year WEEKS. Right now, I have data from 4 years ago. "Date" is already a dimension on my report that pulls by Week, but is there a formula I can use so that a separate "Date" dimension only pulls CY Weeks and PY Weeks?

KPage_0-1708619479349.png

Weeks go beyond 2023 in the table below. I also do not want to set a filter

KPage_1-1708619500167.png

 

Thank you

Labels (4)
1 Reply
Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi @KPage 

If you have access to the data load script, then the recommended approach would be to create a master calendar table in your data set, and to calculate various conditional flags in the calendar. One of the flags could validate the condition that the date belongs to the current year or the prior year. Let's call it CurrentPriorYear_Flag, for example. Then, in your chart expressions, you could request that the flag is equal to 1, like this:

Sum({<CurrentPriorYear_Flag={1}>}   Value)

or in this format:

{<CurrentPriorYear_Flag={1}>}  Sum(Value)

or even like this:


{<CurrentPriorYear_Flag={1}>} [Master Measure 1]

This way, you can ensure consistent performance, even on larger data sets. 

The solution that you asked for, that includes a conditional calculation in a calculated dimension, is highly wasteful, and would only work on small data sets. If you REALLY want to implement something like this, you could use the following formula in your calculated dimension:

AGGR( only( {<set analysis condition that limits the date to 2 years>} Date), Date)

Again, I would not recommend using this solution if your data set is big enough. It will slow things down quite a bit.

Cheers,