Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
njiang126
Contributor
Contributor

Calculate difference between two fields that user selected

njiang126_0-1614188540146.png

I have pivot table, the value is count of items has been sold for each month for the past 24 months. 

User wants to select two months data to compare the difference, for example, user select 2020 January and 2021 January, how to add the third column that can calculate the difference , which is 1826-1027 for the first row?

Thanks, 

 

Nicole 

 

1 Reply
melissapluke
Partner - Creator
Partner - Creator

Hi,

You can add a "before" to your count.

Your first expression is your normal count('field')

Your "Difference" expression is count('field')-before(count('field')).

You can see in my example below, it shows the difference between the two. 

melissapluke_0-1614206289779.png

 

That said, it can get a bit overwhelming if you do not limit your selections. It suggest having a filter for your user to select the appropriate month-year they'd like to compare and then set the calculated condition to only calculated when getselectedcount('datefield')=2

melissapluke_1-1614206421887.png