Skip to main content
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
Partner - Champion
Partner - Champion

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] ) )

View solution in original post

4 Replies
Gysbert_Wassenaar

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


talk is cheap, supply exceeds demand
agigliotti
Partner - Champion
Partner - Champion

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] ) )

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
Partner - Champion
Partner - Champion

ok great!
please mark the anwser as correct to help others.