How to get dynamic end of period date in a set expression
I have general ledger balances which are semi-additive (i.e. you can add across accounts to sum assets in any given period, but it is incorrect to add the balances across the time dimension). I need to build a set expression that will correctly choose the maximum period within a range of periods as part of a set analysis expression.
For instance, when the user has collapses the dimension from individual months, to quarters, or years, the expression should calculate the balance as of the last period in the quarter or year. Essentially, within each row of a straight table or chart, the expression should note the reporting dimension (year, quarter, month), get the maximum possible period for that dimension, and calculate the balance as of that period. So for 2015-Q1, the expression needs to determine that '2015-03' is the [Year-Period] value, and return the balance for that period as the result. Same for Q2, Q3, etc.
Here is a sample of balances by reporting period:
For '2015-Q1', the balance in the expression should be $5,478,268, the balance for the maximum period in that range. Same for the year--if the user clicks to report by year, then 2015 balance should be $5,873,844.
In a straight table I can get Qlikview to indicate the maximum value of the [Year-Period] field, as shown in the table below. However, that doesn't work when referenced in a set expression. (Note that the set values shown have been expanded; actual formula in the expression are below).
This expression returns the correct value for Q4, but for no other.
The question is: How can I dynamically get the maximum value for the [Year-Period] field, for each row, when the dimension is collapsed from periods to quarters and years? This value needs to be referenced in the set expression to drive the calculation of the correct balance at the end of each period.