Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I'm looking for a set analysis expression where if we select an year it has to show previous year sales. Below example data.
Date | Market | Sales |
1/1/2024 | IND | 100 |
1/21/2024 | NAM | 200 |
1/16/2024 | AUS | 600 |
12/15/2023 | IND | 300 |
9/16/2023 | NAM | 400 |
8/26/2023 | AUS | 500 |
4/13/2022 | AUS | 600 |
5/18/2022 | IND | 900 |
6/10/2022 | NAM | 700 |
So I'm looking for a set analysis or a flag in the back end where if I select year it has to show previous year values. Below example.
If I select 2024 from year filter it has to show 2023 values.
Year | Sales 2024 | Sales 2023 |
2024 | 900 | 1200 |
If I select 2023 from year filer it has to show 2022 values
Year | Sales 2023 | Sales 2022 |
2023 | 1200 | 2200 |
Good morning,
Try something like this :
if(GetSelectedCount(OrderDate)=1,sum({$<Year={$(=max(Year)-1)}>}Sales))
Enjoy your Qlik.
Kind regards,
Théo ATRAGIE.
Hello,
Here is used data:
data:
Load *,
Year(Date) as Year
;
LOAD * INLINE [ID,Date, Sales
1,1/1/2022, 100
2,1/1/2022, 200
3,1/1/2023, 300
4,1/1/2023, 400
5,1/1/2024, 500
6,1/1/2024, 600
];
Firstly define 2 variables:
vSelectedYear=GetFieldSelections(Year)
vPreviousYear=GetFieldSelections(Year)-1
Into a table add:
Dimension: =$(vSelectedYear) and Label as Year
Measure1: Sum({<Year={$(vSelectedYear)}>}Sales) and Label as ='Sales For '&ValueList('$(vSelectedYear)')
Measure2: Sum({1<Year={$(vPreviousYear)}>}Sales) and Label as ='Sales For '&ValueList('$(vPreviousYear)')
These are the results:
Best regards,