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

Announcements
Join us in NYC Sept 4th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Brijesh
Contributor II
Contributor II

Handling measures for different time Periods

I have to display the closing_balance for the last month of every period selected. For example if a month is selected the closing balance for that month should be displayed.
However if a quarter is selected the closing balance for the last month of that quarter needs to displayed.And same for the year where the closing balance of the last month of that year needs to be shown. I got the above logic to work using the below function.

FirstSortedValue(Aggr(Sum([YTD_Net_Amount]+Yearly_Opening_Balance), [Time_Sid.Calendar.MonthYear]), -Aggr([Time_Sid.Calendar.MonthYear], [Time_Sid.Calendar.MonthYear]))

However the above function doesnt work when I add other attributes into that report. I have an Account dimension whose drill down goes from Account_Level_1 thru Account_Level_7 and then to account number. When I bring  Account dimension into that report it doesnt give me the expected output. I am trying to figure how I can still aggregate closing balance by account number and still show the correct aggregated closing balance for the ending period.
I tried something like this where it works correctly at the month level but it sums up the closing balance when rolled up to Quarter level or Year level

sum(aggr(FirstSortedValue(Aggr(SUM([YTD_Net_Amount]+Yearly_Opening_Balance),Account_Number,[Time_Sid.Calendar.MonthYear]), -Aggr([Time_Sid.Calendar.MonthYear], [Time_Sid.Calendar.MonthYear],Account_Number)),[Time_Sid.Calendar.MonthYear],Account_Number))


Any thoughts on how I need to handle this?

Labels (3)
1 Solution

Accepted Solutions
Brijesh
Contributor II
Contributor II
Author

I have not gotten  any responses but thought will let the community know how I resolved this particular issue. Here is the expression that did the trick for me.

If((GetPossibleCount([Time_Sid.Calendar.Quarter])=1)  ,

(sum(YTD_Net_Amount))

,

if((GetPossibleCount([Time_Sid.Calendar.Year])=1)

,(sum(IF(Time_Sid.Calendar.MonthYear = Aggr(NODISTINCT Max({1} Time_Sid.Calendar.MonthYear),[Time_Sid.Calendar.Quarter],Time_Sid.Calendar.Year), YTD_Net_Amount)))

,

(sum(IF(Time_Sid.Calendar.MonthYear = Aggr(NODISTINCT Max({1} Time_Sid.Calendar.MonthYear),Time_Sid.Calendar.Year), YTD_Net_Amount)))

))

View solution in original post

2 Replies
Brijesh
Contributor II
Contributor II
Author

Any thoughts anyone?

Brijesh
Contributor II
Contributor II
Author

I have not gotten  any responses but thought will let the community know how I resolved this particular issue. Here is the expression that did the trick for me.

If((GetPossibleCount([Time_Sid.Calendar.Quarter])=1)  ,

(sum(YTD_Net_Amount))

,

if((GetPossibleCount([Time_Sid.Calendar.Year])=1)

,(sum(IF(Time_Sid.Calendar.MonthYear = Aggr(NODISTINCT Max({1} Time_Sid.Calendar.MonthYear),[Time_Sid.Calendar.Quarter],Time_Sid.Calendar.Year), YTD_Net_Amount)))

,

(sum(IF(Time_Sid.Calendar.MonthYear = Aggr(NODISTINCT Max({1} Time_Sid.Calendar.MonthYear),Time_Sid.Calendar.Year), YTD_Net_Amount)))

))