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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
mateo_florence
Partner - Contributor
Partner - Contributor

Calculate Aggregates

Hi!

I need to calculate a KPI, I put an example to explain it:

DateID ATMAmount
14/01/2019221.000,00
14/01/2019995.000,00
10/01/2019223.000,00
17/12/20184910.000,00
22/11/2018498.000,00
29/10/2018493.000,00

 

I need to SUM the Amount of the Max Date of each ATM, so in this case i have to sum the 'blue' values.

Then my KPI is: 16.000,00

DateID ATMAmount
14/01/2019221.000,00
14/01/2019995.000,00
10/01/2019223.000,00
17/12/20184910.000,00
22/11/2018498.000,00
29/10/2018493.000,00


Any Suggestions? Can i do it using set analysis??

Thanks!!

Labels (2)
1 Solution

Accepted Solutions
agigliotti
MVP
MVP

i suggest you working on the script as below:
temp_table:
load
[ID ATM],
max(Date) as [Date Max]
Resident your_table group by [ID ATM];

Left Join (your_table)
load * Resident temp_table;

DROP Table temp_table;

finally in UI use the below expression for your KPI:
=sum( if( Date = [Date Max], Amount ) )

 

OTHERWISE with no modification on the script, use the below expression in KPI:

=sum( aggr( FirstSortedValue( Amount, -Date ), [ID ATM] ) )

The Power of shining a light on the dark side of your data.
Follow me on my LinkedIn | Know Gamma Informatica at gammainformatica.it

View solution in original post

4 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Use ID ATM as dimension and use max(Date) and firstsortedvalue(Amount, -Date) as expressions.


talk is cheap, supply exceeds demand
agigliotti
MVP
MVP

i suggest you working on the script as below:
temp_table:
load
[ID ATM],
max(Date) as [Date Max]
Resident your_table group by [ID ATM];

Left Join (your_table)
load * Resident temp_table;

DROP Table temp_table;

finally in UI use the below expression for your KPI:
=sum( if( Date = [Date Max], Amount ) )

 

OTHERWISE with no modification on the script, use the below expression in KPI:

=sum( aggr( FirstSortedValue( Amount, -Date ), [ID ATM] ) )

The Power of shining a light on the dark side of your data.
Follow me on my LinkedIn | Know Gamma Informatica at gammainformatica.it
mateo_florence
Partner - Contributor
Partner - Contributor
Author

Hello Agigliotti!!

Thank you for your answer!

I have used your expression in KPI and it is what i need!!

agigliotti
MVP
MVP

ok great!
please mark the anwser as correct to help others.
The Power of shining a light on the dark side of your data.
Follow me on my LinkedIn | Know Gamma Informatica at gammainformatica.it