Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Divyanshu
Contributor II
Contributor II

To roll back to the last 4 quarters based on selection

Hi All,

I am having a line chart with the quarter and year in the x-axis.

If I am selecting Q3-2021 so dynamically in the x-axis it should show Q4-2020>>Q1-2021>>Q2-2021>>Q3-2021.

Is it possible to achieve this using any any function or expression?

 

Thanks in advance

Labels (2)
1 Reply
GaryGiles
Specialist
Specialist

Not sure of how your QuarterYear field is calculated and/or the Dates are used in your data, but the following is the approach that you could use.

In your dimension, use:

=aggr(Only({1<[Date Field]={"<=$(=Date(max({1<QuarterYear=$::QuarterYear>} [Date Field])))>=$(=Date(Addmonths(max({1<QuarterYear=$::QuarterYear>}[Date Field]),-12)))"}>} [QuarterYear]),[QuarterYear])

The {1< tells Qlik to ignore selections and the set analysis will limit the QuarterYear only those within a year of the maximum [Field Date] of the available data.  As you filter on QuarterYear, the max([Date Field]) will adjust.

In you measure, you will need to include [QuarterYear]= in your set analysis to ignore the selection of [QuarterYear], something like:

sum({$<[QuarterYear]=>} Value)

You may need to add other set analysis to the dimension expression depending on what other field might be filtered.