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

Announcements
Join us at Qlik Connect 2026 in Orlando, April 13–15: Register Here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Manni_SM
Creator
Creator

Set analysis measures

Hi all

I want to calculate below measures in qliksense cloud like by like analysis 

I have fields like :

Total sales

Orderdate

Base sales ( order quantity*product price) as sales.

 

Now below measures need to calculate:

1.Current month sales

2 previous month sales

3. Month on month sales variance 

4.current month vs previous month sales 

How can I do this ?

 

 

4 Replies
marcus_sommer

The simplest method is to apply 4 expressions, like:

sum({< Period = {"$(=max(Period))"}>} Sales)
sum({< Period = {"$(=max(Period)-1)"}>} Sales)
sum({< Period = {"$(=max(Period))"}>} Sales) / sum({< Period = {"$(=max(Period)-1)"}>} Sales)
sum({< Period = {"$(=max(Period))"}>} Sales) - sum({< Period = {"$(=max(Period)-1)"}>} Sales)

whereby Period is a calendar-field of: Year * 12 + Month. Important is further no to include any date-related field within the charts.

WeLoveQlik
Partner - Creator
Partner - Creator

I would create a Month Index using the script.

Steps:

1. In your fact table create a key that is YYYYMM (its important month is 2 digits, here)

2. Do a resident load of all distinct Values in you YearMonthKey you created in step 1

3. Load those distinct values with a ROWNO() to create an index. 

4. Create a Max(Index) Variable and all the prior period variables. For example, Max(Index)-1.  Use those in your set analysis in the same manner described by @marcus_sommer's response.

Both are very similar just done in a slightly different way!

IPC Global: ipc-global.com
Manni_SM
Creator
Creator
Author

Shall I create a field in master calendar?

Year * 12 + Month as period ? 

marcus_sommer

That's my preferred way to create a continuous information to months over n years. The logic is simple and could be easily integrated within the calendar-creation. Similar approaches are also applicable by weeks and quarters, the values are immutable and it's possible to revers the calculation to get the underlying date-information again.

Methods which using a record-logic - per distinct extract and rowno/recno or within interrecord-functions in sorted resident-loads - are often more complex and require usually more efforts - especially if not only the months are flagged. But if the period-information have some kind of gaps and it's important to consider them then you would need such an approach.