Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
nishzuana
Contributor
Contributor

Expression to show last 4 quarters data only

I have a data which consists quarter details (2022Q1, 2022Q2, 2022Q3, 2022Q4,2023Q1), I'm using it in dimension.

I want to display only 4 quarter data (past three and current quarter) in x axis,. I can use if condition in expression to manually filter out 2022Q1 but when 2023Q2 comes again I'll have to do the filter on 2022Q2. Is there any dynamic way of achieving this

3 Replies
Or
MVP
MVP

Ideally, you'd approach this by using Quartername(Date) as your dimension instead of a string such as 2022Q1 and then use date functions. However, you could also just use string functions to work around the issue, e.g. >Left(max(quarter),4)-1 & right(max(quarter),2).

AronC
Partner - Creator II
Partner - Creator II

Do you have a periodId in your datamodel?

If so then you could just use:
sum({<PeriodId = {">=$(=Max(PeriodId)-11)<=$(=Max(PeriodId))"},Year=, Month,Quarter>}#Amount)

 

Otherwise you change PeriodId to work out for your dates if you have a date-field. Try something like:

sum({<Datum= {">=$(=Monthstart(Addyears(today(),-1)))<=$(=Today())"},Year=, Month,Quarter>}#Amount)

 

In your chart, you just add Quarter as dimension. In the measure you use the set-expression above.

 

nishzuana
Contributor
Contributor
Author

FirstSortedValue({$<[METRIC_NAME]={'State'},Dimension={"=rank(Dimension)<=5"}>}[Value],-EVENT_TIMESTAMP). But the issue is every quarter I have to increase the value till last quarter it was giving me desired result but as soon as new quarter starts I had to increase =rank(Dimension)<=6