Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
vikasshana
Creator II
Creator II

set analysis expression to show sales of previous year if I select an year

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
Labels (2)
2 Replies
theoat
Partner - Specialist
Partner - Specialist

Good morning,
Try something like this :

if(GetSelectedCount(OrderDate)=1,sum({$<Year={$(=max(Year)-1)}>}Sales))

Enjoy your Qlik.

Kind regards,
Théo ATRAGIE.

Nicolae_Alecu
Creator
Creator

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

Nicolae_Alecu_0-1711706697980.png

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:

Nicolae_Alecu_1-1711707029667.png

Nicolae_Alecu_2-1711707040998.pngNicolae_Alecu_3-1711707051395.png

Nicolae_Alecu_4-1711707062638.png

Best regards,