Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
ghaliabed
Partner - Creator
Partner - Creator

Sum for the Latest Month across the Years

Hello

Goal:

  • Create a Master Measure for Total Number of Employees  to be used against any dimension
  • Total Number of Employees is a cumulative value so it is not a direct Sum, ie: it should be the Sum of Employees found in the Latest Month.

Examples below on data and output chart needed.

Currently i tried the below Set Expression:

 

 

 

SUM ({$< [Year Month]={$(=MAX([Year Month]))} >} [Number of Employees])

 

 

 

However, when i place this measure in a bar chart grouped by the Year, only the Latest Year will get a value while the rest will be ZERO.

Ex: if Latest Month in the data is = 2020-08, but knowing i have months in the previous years

Fiscal YearTotal Employee
20190
202010

 

Example of Data Present:

Calendar:

DateYearFiscal YearYear Month
2019-08-01201920192019-08
2019-09-01201920192019-09
2019-10-01201920202019-10

 

Fact Table:

DateRegionHead Count

DateRegionNumber of Employees
2019-08-01A1
2019-08-01B1
2019-09-01A2
2019-09-01B2
2019-09-01C2
2019-10-01A3
2019-10-01B3
2019-10-01C3

 

Target Measure/Chart:

Table Chart that will show this:

Fiscal YearTotal EmployeeLogic
20196Sum of the Regions found in Month 2019-09 ; the last month of the Fiscal Year 2019
20209Sum of the Regions found in Month 2019-10 ; the last month of the Fiscal Year 2020
26 Replies
ghaliabed
Partner - Creator
Partner - Creator
Author

I found a possible way to do this but not fully working yet.

Using the FirstSortedValue function:

FirstSortedValue( Aggr( Sum( Number of Employee) , [Year Month] ), -Num([Year Month] ) )

Great post here:

https://community.qlik.com/t5/Qlik-Design-Blog/Additive-and-Non-Additive-Numbers/bc-p/1687631#M8701

 

However it still doesn't work fully for my case as when i add dimensions other than Calendar it only gives a value for one of the values but not all of them.

Like image below:

Capture.PNG

lorenzoconforti
Specialist II
Specialist II

You probably need to add the extra dimensions to your aggregation function

Based on the formula in your chart:

FirstSortedValue( Aggr( Sum(SignedData) , [Year Month Number], ACCOUNT_TYPE ), -Num([Year Month Number] ) )

 

ghaliabed
Partner - Creator
Partner - Creator
Author

I tried adding it in the Aggr part, but when i did no values were returned at all.

Plus i need this to stay dynamic as in regardless what dimension i add to the chart i want it to show value.

FirstSortedValue( Aggr( Sum( SignedData ) , [Year Month Number], ACCOUNT_TYPE ), -Num([Year Month Number]) )

 

Capture.PNG 

lorenzoconforti
Specialist II
Specialist II

Can you post the dashboard or recreate the issue in a new one?

ghaliabed
Partner - Creator
Partner - Creator
Author

Please find attached the dashboard i am working with

 

lorenzoconforti
Specialist II
Specialist II

This works for the sample table (see attached):

=FirstSortedValue(aggr(sum(SignedData), ACCOUNT_TYPE, [Year Month Number] ),-aggr(only([Year Month Number]) , ACCOUNT_TYPE, [Year Month Number]))

To make it into a master measure you would need to add all the dimensions you'll likely to use in your charts in the two aggregation functions; it should work

ghaliabed
Partner - Creator
Partner - Creator
Author

It doesn't seem to be working across all cases.

in this example not all Account Types are being calculated and also if you want to show total at level of the chart, it does not show but is just BLANK.

Pick:

FirstSortedValue(aggr(sum(SignedData), ACCOUNT_TYPE, [Year Month Number] ),-aggr(only([Year Month Number]) , ACCOUNT_TYPE, [Year Month Number]))

 

Capture.PNG

lorenzoconforti
Specialist II
Specialist II

This table shows different dimensions; you need to add them to the formula

 

ghaliabed
Partner - Creator
Partner - Creator
Author

yes the dimensions used in the chart already added in the Formula, and was getting results in the image