Forum Discussion
Get the latest value from a column based on another date column
Hi,
I have a table that looks similar to this.
| Item | Date | Price |
| A | 1st July 2020 | 300 |
| A | 10th May 2020 | 100 |
| A | 4th Aug 2020 | 200 |
| B | 3rd Mar 2020 | 450 |
| B | 15th Sept 2020 | 560 |
I want to get the latest value for 'Price' for each item.
The output should look like this
| Item | Latest Price |
| A | 200 |
| B | 560 |
How can this be achieved?
7 Replies
- FrankAT
Community Champion
Hi Anonymous
you can it it like this:
Latest Price = CALCULATE( MAX('Table'[Price]), FILTER( ALLEXCEPT('Table','Table'[Item]), MAX('Table'[Date]) = 'Table'[Date] ) )With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)- AnonymousNot applicable
Thank you for the answer,
I have a few follow-up questions,
How can I get the other column values of the row which had the latest price value for the item?
Also, I want to group the rows and find the latest price for the item as well as the group.
Similar to the example I have shown belowItem Grp Date Tag Price A 1 10th May 2020 Tag1 670 A 2 14th June 2020 Tag2 100 A 2 1st April 2020 Tag3 500 A 2 13th August 2020 Tag4 400 A 1 5th Sept 2020 Tag5 590 B 1 4th Feb 2020 Tag6 110
The output if possible should create another table, with the following output.Item Grp Date Tag Latest Price A 1 5th Sept 2020 Tag5 590 A 2 3rd August 2020 Tag4 400 B 1 4th Feb 2020 Tag6 110 - AnonymousNot applicable
hi Anonymous - You can follow the below steps to achieve the required results.
1. Create a calculated column Item + Group
Item&Grp = 'Test Table'[Item] & "-" & 'Test Table'[Grp]2. Update the Rank measure as belowDate Rank =IF (HASONEVALUE ( 'Test Table'[Item&Grp] ),RANKX ( ALLSELECTED ( 'Test Table'[Date], 'Test Table'[Tag] ), ( [Sort Date] ), ,DESC, Skip ))Filter the specific visual for records where "Date Rank" = 1 as seen belowPlease mark the post as a solution and provide a 👍 if my comment helped with solving your issue. Thanks!
- AnonymousNot applicable
hi Anonymous - you can create a measure to rank all records by Date and Item as shown below
1. Sort Date = MAX( 'Test Table'[Date] )
2. Date Rank =
IF (HASONEVALUE ( 'Test Table'[Item] ),RANKX ( ALLSELECTED ( 'Test Table'[Date] ), ( [Sort Date] ), ,DESC, Skip ))3. "Date Rank" creates a rank for each Item as seen below4. Add a visual level filter to show only records where "Date Rank" = 1 as seen below - Ashish_Mathur
Super User
- v-diye-msft
Community Support
Hi Anonymous
If the above posts help, please kindly mark it as a answer to help others find it more quickly. thanks!
If not, please kindly elaborate more.