Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
WalidChoukri
Contributor III
Contributor III

Get the latest value in a pivot table

Hello Everyone,

I have a sample data like below :

WalidChoukri_0-1618234020786.png

and I tried to represent the sum of quantity in a pivot table, the problem is i want to display the latest date data for each month and not the sum,when i collapse the table in each month.

WalidChoukri_1-1618234297018.png

WalidChoukri_2-1618234392746.png

The required values : Article  Month    Avril     Mai
                                               a                           15          25
                                               b                           13          17

I tried the following expression :  Max(Aggr(Sum(Quantity) ,Month,Date,Article)) and i got this.

WalidChoukri_4-1618234797450.png

I need an expression so instead of getting the maximum value for each month i get the latest one, any ideas ?

Thank you so much.

 

                                             

1 Solution

Accepted Solutions
eddie_wagt
Partner - Creator III
Partner - Creator III

You can solve this by using FirstSortedValue function like this

FirstSortedValue(aggr(Sum(Quantity),Date,Article),-Date)

View solution in original post

4 Replies
Marcos_Ferreira_dos_Santos

Hi WalidChoukri

Have you solved this issue ?

I did a test and got it by adding a "flag" column LastDay, filled with yes or no. Then I tried this expression -  Sum({<LastDay = {"yes" }>}Quantity) -out and it worked.

That's is just a suggestion, if you wish. Sometimes in Qlik is good to "solve" some issues in script/load time and then have the things more "prepared" for the visualizations.

Best regards

Marcos

eddie_wagt
Partner - Creator III
Partner - Creator III

You can solve this by using FirstSortedValue function like this

FirstSortedValue(aggr(Sum(Quantity),Date,Article),-Date)
WalidChoukri
Contributor III
Contributor III
Author

Thank you so much it did work

WalidChoukri
Contributor III
Contributor III
Author

Thank you, i thought of doing a flag but the file I provided is just a sample, it'll be much difficult to do a flag with the database I have