Forum Discussion
RuiPatricio
5 years agoFrequent Visitor
Select most recent row for each item
I have a Table which is created though a UNION of some queries. The table has many rows for each widget that I care about -- basically one row for every day. So it looks somewhat like this: Wid...
- 5 years ago
Hi RuiPatricio
You can do this in DAX (1 below) or in the Query editor (2). See it all at work in the attached file.
1. Create a new calculated table
Table2 = FILTER ( Table1, Table1[Date] = CALCULATE ( MAX ( Table1[Date] ), ALLEXCEPT ( Table1, Table1[Widget Id] ) ) )2. Place the following M code in a blank query to see the steps.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZY05DoAwDAT/4jpSDnJAGcLxiCgFVBT8vwaBQRulGks7GudMkQR10kqjjL7P/dyOj5GKyDS2gmGOj/AWHAodM0GhEixzgoJHwTFnKFSCZy6PkFohMFd4EVDomfCh2gfcU7tr9QvlAg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Widget Id" = _t, Date = _t, Data2 = _t, Data2_2 = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Widget Id", type text}, {"Date", type date}, {"Data2", type text}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Widget Id"}, {{"Count", each Table.Max(_,"Date") }}), #"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "Count", {"Date", "Data2", "Data2_2"}, {"Date", "Data2", "Data2_2"}), #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Count",{{"Date", type date}, {"Data2", type text}, {"Data2_2", type text}}) in #"Changed Type1"Please accept the solution when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Ashish_Mathur
Super User
5 years ago- RuiPatricio5 years agoFrequent Visitor
thanks Ashish_Mathur
I was not clear in my question (& I've edited my post).
Not every widget will have a row for the latest day; the data I'm looking for is the latest data for that particular widget
- Ashish_Mathur5 years ago
Super User
My solution still works. See the screenshot.