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

Announcements
Qlik Connect 2026! Turn data into bold moves, April 13 -15: Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
SingSing16
Contributor III
Contributor III

FirstSortedValue and Aggr

I have issue with creation of dimension including FirstSortedValue as well Aggr.
I already created some measure including value which I am interested but in this case I need to create chart including this values as dimension.

Project_Number Project_History_Field Project_History_Value Historical_field_change_date
P123 Project_Status Not started 2022-10-11
P123 Username Lisa M. 2020-12-17
P123 Project_Status In progress 2023-01-02
P456     Project_Status On-hold 2023-01-15
P789` Project_Stage Review 2020-11-15
P789 Project_Status In progress 2020-12-28
P789 Project_Status Cancelled 2021-12-12

 

I need to gain only one Project_History_Value  according to Project_Status (in Project_History_Field) for single Project_Number according to the newst date.

I tried to create dimension according to this:

=FirstSortedValue({<[Project_History_Field]={"Project_Status"}>}[Project_History_Value],
-Aggr(Max([Historical_field_change_date]),Project_History_Field))

Formally it works but but doesn't if I want to create table or chart with it.

Please help me.

Best Regards

Labels (1)
4 Replies
KGalloway
Creator II
Creator II

Will this work?

KGalloway_0-1674512796909.png

I edited your formula slightly and used FirstSortedValue({<[Project_History_Field]={"Project_Status"}>}[Project_History_Value],-[Historical_field_change_date])

SingSing16
Contributor III
Contributor III
Author

Hello, 

I created measure  at the beginning excatly the same as you wrote, but I need to create dimension for my chart.

Because of that I tried this with Aggr:

=FirstSortedValue({<[Project_History_Field]={"Project_Status"}>}[Project_History_Value],
-Aggr(Max([Historical_field_change_date]),Project_History_Field)) 

but it does not works on chart.

Any other idea?

 

KGalloway
Creator II
Creator II

What about adding fields in the load script to identify the most recent changed record and then apply its status to all of the records for that project as a new field?

raw:
load * inline [
Project_Number, Project_History_Field, Project_History_Value, Historical_field_change_date
P123, Project_Status, Not started, 2022-10-11
P123, Username, Lisa M., 2020-12-17
P123, Project_Status, In progress, 2023-01-02
P456, Project_Status, On-hold, 2023-01-15
P789, Project_Stage, Review, 2020-11-15
P789, Project_Status, In progress, 2020-12-28
P789, Project_Status, Cancelled, 2021-12-12

]
;

left Join
load
Project_Number,
max(Historical_field_change_date) as Most_Recent_Change_Date
resident raw
where Project_History_Field = 'Project_Status'
group by Project_Number;

left join
Load
Project_Number,
Project_History_Value as Most_Recent_Status
resident raw
where Historical_field_change_date = Most_Recent_Change_Date;

 

This gave me the following table:

KGalloway_0-1674570783205.png

 

vinieme12
Champion III
Champion III

to create a calculated dimension wrap the expression in Aggr() as below 

 

=Aggr(FirstSortedValue({<Project_History_Field={'Project_Status'}>} Project_History_Value,-Historical_field_change_date),Project_Number)

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.