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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
bdroesch
Contributor
Contributor

Set Analysis: Need To Look At Data From Previous Month

Hi All,

I have month end balances for different accounts. I am trying to create a table where a user can select multiple account numbers and multiple dates to view the current balance as well as the balance from the previous month end.

Below are examples of the results I would be trying to produce where Account, AsOfDate & CurrBalance are the only fields that are being loaded in via the data loader. (So PrevMonthEndDate & PrevBalance would need to be calculated).

    

AccountAsOfDatePrevMonthEndDateCurrBalancePrevBalance
11116/30/20185/31/201810001100
22226/30/20185/31/201820002200
33336/30/20185/31/201815001600

AccountAsOfDatePrevMonthEndDateCurrBalancePrevBalance
11116/30/20185/31/201810001100
11115/31/20184/30/201811001200
11114/30/20183/31/201812001300
11113/31/20182/28/201813001400
11112/28/20181/31/20181400

1500

I have been trying to use set analysis but I am running in to some problems. I created a variable vPrevMonth with the following definition.

vPrevMonth

=MonthEnd(AddMonths([AsOfDate],-1))



Then I created a measure in the table for PrevBalance with the following formula:

=SUM({$<[AsOfDate] = {'=$(vPrevMonth)'} >} [CurrBalance])

This formula just shows the Current Balance for the AsOfDate. For example, below I just selected my AsOfDate to be 06/30/2018.

AccountAsOfDatePrevMonthEndDateCurrBalancePrevBalance
11116/30/20185/31/201810001000
22226/30/20185/31/201820002000
33336/30/20185/31/201815001500

So I believe this means that in the set analysis, the {'=$(vPrevMonth)'} is searching through all possible AsOfDates and outputting a list of previous month end dates (so it is not restricted to look at only AsOfDate=06/30/2018).

Additionally, with this formula if I select two AsOfDates then it shows a PrevBalance =0. Please see below where I select AsOfDate to be either 6/30/2018 or 5/31/2018.

AccountAsOfDatePrevMonthEndDateCurrBalancePrevBalance
11116/30/20185/31/201810000
11115/31/20184/30/201811000

Thank you,

Brian

16 Replies
bdroesch
Contributor
Contributor
Author

Hi Sunny,

I have attached a sample of similar data to what I have been working with.  I adjusted vPrevMonth to remove the first "=" at the beginning of the equation.

Please disregard that there is no data for 06/30/2018. I have been testing with As Of Dates of 5/31/2018 or older.

Thank you,

Brian

sunny_talwar

Few things to note...

1) MonthEnd() gives a timestamp down to the last second of the Month... SO, MonthEnd() today will be

07/31/2018 23:59:59. But since your AsOfDate is most likely just a date, you need to use Floor to remove Time and use Date for formatting

2) You were using AsOfDate as dimension... but if you are looking to see this by selecting a single date... I would suggest you against using it as a dimension and rather use it as an expression...

see if this is what you wanted

Capture.PNG

bdroesch
Contributor
Contributor
Author

Thanks Sunny. This does work but only if you are selecting 1 date. I guess this is a limitation if you are setting AsOfDate as an Expression.  If I make it a dimension then it will not work as currently constructed.

Any thoughts on how I could satisfy multiple date selections?

Would I need to use the AGGR() function to group by "AsOfDate"?

Thank you,

Brian

sunny_talwar

In that case, try this

Dimension

ID

AsOfDate

Expression

=Sum([CurrBalance])

=$(vPrevMonth)

=Aggr(Above(Sum({<AsOfDate>} [CurrBalance])), ID, (AsOfDate, (NUMERIC, ASC)))


Capture.PNG

bdroesch
Contributor
Contributor
Author

Thank you Sunny. This worked for me!

Do you mind just explaining the formula below? Specifically what {<AsOfDate>} does.

=Aggr(Above(Sum({<AsOfDate>} [CurrBalance])), ID, (AsOfDate, (NUMERIC, ASC)))

sunny_talwar

Let me explain with an example... when we are selecting 5/31 and 4/30.... we only have values for those two months.... but for previous month we want to see 4/30 and 3/31... in order to be able to see 3/31... we need to ignore selection in AsOfDate.... which allow Above() function to look one Month above value.

bdroesch
Contributor
Contributor
Author

Thank you for your help Sunny!