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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
joshua1990
Post Prodigy
Post Prodigy

Latest Value per Article

Hi all!

I have a big table that contains dimensional an transaction data:

Article Dim 1 Dim 2 Dim 3 Value Date
A          
A          

 

Now I would like to get the latest [Value] based on the Date column.

I know, DAX would be here the best way, but I need it in PQ.

 

How would you do that? Filter for each Article the last available row based on the Date column.

 

 

Thanks in advance

1 ACCEPTED SOLUTION
ValtteriN
Community Champion
Community Champion

Hi,

Here is one way to do this:
Example data:

ValtteriN_2-1676197654736.png

 




1. Duplicate the query for use in step 3
2. Group the query by date and article:

#"Removed Other Columns" = Table.SelectColumns(#"Sorted Rows",{"Date", "Article"}),
#"Grouped Rows" = Table.Group(#"Removed Other Columns", {"Article"}, {{"LatestDate", each List.Max([Date]), type nullable date}})
in
#"Grouped Rows"

ValtteriN_0-1676197565061.png

 

3. Merge the grouped query and filter nulls away after expanding:
#"Merged Queries" = Table.NestedJoin(#"Sorted Rows", {"Date"}, #"Table (27)", {"LatestDate"}, "Table (27)", JoinKind.LeftOuter),
#"Expanded Table (27)" = Table.ExpandTableColumn(#"Merged Queries", "Table (27)", {"LatestDate"}, {"LatestDate"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded Table (27)", each ([LatestDate] <> null))
in
#"Filtered Rows"


4. End result:

ValtteriN_1-1676197630107.png

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/








Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
serpiva64
Solution Sage
Solution Sage

Hi,

you can try by grouping

 

 

then after expanding you have to filter for one article

= Table.SelectRows(#"Expanded AllRows", each ([MinDate] = #date(2022, 1, 24)))

and replace in your formula bar

= Table.SelectRows(#"Expanded AllRows", each ([MinDate] = [Order Date]))

 

Pay attention if you have duplicates in your table (in that case you have to add grouping f.e. you have sold the same article to 2 customer in the same day) !!!

If this post is useful to help you to solve your issue, consider giving the post a thumbs up and accepting it as a solution!

 

ValtteriN
Community Champion
Community Champion

Hi,

Here is one way to do this:
Example data:

ValtteriN_2-1676197654736.png

 




1. Duplicate the query for use in step 3
2. Group the query by date and article:

#"Removed Other Columns" = Table.SelectColumns(#"Sorted Rows",{"Date", "Article"}),
#"Grouped Rows" = Table.Group(#"Removed Other Columns", {"Article"}, {{"LatestDate", each List.Max([Date]), type nullable date}})
in
#"Grouped Rows"

ValtteriN_0-1676197565061.png

 

3. Merge the grouped query and filter nulls away after expanding:
#"Merged Queries" = Table.NestedJoin(#"Sorted Rows", {"Date"}, #"Table (27)", {"LatestDate"}, "Table (27)", JoinKind.LeftOuter),
#"Expanded Table (27)" = Table.ExpandTableColumn(#"Merged Queries", "Table (27)", {"LatestDate"}, {"LatestDate"}),
#"Filtered Rows" = Table.SelectRows(#"Expanded Table (27)", each ([LatestDate] <> null))
in
#"Filtered Rows"


4. End result:

ValtteriN_1-1676197630107.png

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/








Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.