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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
joshua1990
Post Prodigy
Post Prodigy

Latest extract per article

Hi community!

To ensure every changing dimension for each week is captured we have a weekly extract for all our articles.

The result is structued like this:

Year-Week Extract Article Dim 1 Dim 2
2023-01 A 1 1
2023-02 A 1 1
2023-03 A 2 1
2023-01 B 1 1

 

Now I would like to get for every article the latest available row.

 

How would you do that in PQ?

1 ACCEPTED SOLUTION
ppm1
Solution Sage
Solution Sage

Here's one way to do it, with a Group following by a Transform step using Table.Max. Paste the below into a blank query (Advanced Editor) to see how it works.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtY1MFTSUXIEYkMwjtWBiRvhEDeGihuhiYPUOSHUxwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Year-Week Extract" = _t, Article = _t, #"Dim 1" = _t, #"Dim 2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year-Week Extract", type date}, {"Article", type text}, {"Dim 1", Int64.Type}, {"Dim 2", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Article"}, {{"AllRows", each _, type table [#"Year-Week Extract"=nullable date, Article=nullable text, Dim 1=nullable number, Dim 2=nullable number]}}),
    Custom1 = Table.TransformColumns(#"Grouped Rows", {{"AllRows", each Table.Max(_, "Year-Week Extract")}}),
    #"Expanded AllRows" = Table.ExpandRecordColumn(Custom1, "AllRows", {"Year-Week Extract", "Dim 1", "Dim 2"}, {"Year-Week Extract", "Dim 1", "Dim 2"})
in
    #"Expanded AllRows"

 

 

Pat

Microsoft Employee

View solution in original post

1 REPLY 1
ppm1
Solution Sage
Solution Sage

Here's one way to do it, with a Group following by a Transform step using Table.Max. Paste the below into a blank query (Advanced Editor) to see how it works.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtY1MFTSUXIEYkMwjtWBiRvhEDeGihuhiYPUOSHUxwIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Year-Week Extract" = _t, Article = _t, #"Dim 1" = _t, #"Dim 2" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year-Week Extract", type date}, {"Article", type text}, {"Dim 1", Int64.Type}, {"Dim 2", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Article"}, {{"AllRows", each _, type table [#"Year-Week Extract"=nullable date, Article=nullable text, Dim 1=nullable number, Dim 2=nullable number]}}),
    Custom1 = Table.TransformColumns(#"Grouped Rows", {{"AllRows", each Table.Max(_, "Year-Week Extract")}}),
    #"Expanded AllRows" = Table.ExpandRecordColumn(Custom1, "AllRows", {"Year-Week Extract", "Dim 1", "Dim 2"}, {"Year-Week Extract", "Dim 1", "Dim 2"})
in
    #"Expanded AllRows"

 

 

Pat

Microsoft Employee

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors
Top Kudoed Authors