Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
nate_ak
Contributor III
Contributor III

Subtract Previous Month From Current Month with Conditions

I have a variable I've developed with a different tool that is the equivalent of 

Sum(CurrMonBal - PrevMonBal) Where CurrMonEnteredIndicator = "N".

I'd like do accomplish that in Qlik Sense, but I'm getting stuck on the subtraction of CurrMonBal and PrevMonBal within a single equation. I've written the below set analysis to demonstrate the direction I'm trying to go, but as you'll see it calculates:

(Sum(CurrMonBal) Where CurrMonEnteredIndicator = "N") - Sum(PrevMonBal).

This does not give me accurate results. Is there a way to accomplish my initial equation with the below data. 

Sum({$<
[LPM.Year Month] = {"$(=Max([LPM.Year Month]))"},
[LPM.Note Entered This Month Indicator] = {'N'}
>}[LPM.Note Bank Share Ledger Balance]) 

- 

Sum({$<
[LPM.Year Month] = {"$(=Max([LPM.Year Month])-1)"}
>}[LPM.Note Bank Share Ledger Balance])

 

4 Replies
Anil_Babu_Samineni

Expression looks okay - What is not accuracy?
Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Anonymous
Not applicable

I believe you also need the (CurrMonEnteredIndicator  = 'N') condition for the second sum, something like:

Sum({$<
[LPM.Year Month] = {"$(=Max([LPM.Year Month]))"},
[LPM.Note Entered This Month Indicator] = {'N'}
>}[LPM.Note Bank Share Ledger Balance]) 

- 

Sum({$<
[LPM.Year Month] = {"$(=Max([LPM.Year Month])-1)"},
[LPM.Note Entered This Month Indicator] = {'N'}
>}[LPM.Note Bank Share Ledger Balance])

 Would that work?

nate_ak
Contributor III
Contributor III
Author

The syntax is ok and the measure returns results, but they are incorrect. I've QA'd against an already existing measure in a separate application that we are moving away from. 

My formula here takes the sums the balance of the current month where indicator equals N and then subtracts the balance of the previous month. I'd like the formula to sum the result of current month minus previous month and THEN consider the indicator. 

Initially I assumed both methods would return the same results. But I'm able to test both ways in the other application (Web Intelligence) and confirm that they indeed produce different results. 

nate_ak
Contributor III
Contributor III
Author

Phin, thank you for the suggestion - I gave it a try with no success though. Results are still incorrect.