cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PZUDGW
Helper I
Helper I

Aggregate table for dataflow

I'd like to aggregate a table for my dataflow.  The table is down below. I'd like to have:

  • for each distinct REFOBJECT ID,
  • the latest PMCVALIDFROM,
  • and corresponding PMCRENTAMOUNT + PMCSCORINGPOINT

Can I use the option 'Group by' and if so, how?

Knipsel.JPG

1 ACCEPTED SOLUTION
Jimmy801
Community Champion
Community Champion

Hello @PZUDGW 

 

use Table.Group and within the group-function Table.Max to get your desired result. Here an example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI01jM01DMyADHBOFYHKmEBlzACY7iEqZ6hEUTCGIxBEk5AloGFnoGhnqElilEwCSOIBMIoJ4jlBsYQCahRsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"REFOBJECT ID" = _t, PMCVALIDFROM = _t, PMCRENTAMOUNT = _t, PMCSCORINGPOINT = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"REFOBJECT ID", type text}, {"PMCVALIDFROM", type date}, {"PMCRENTAMOUNT", Int64.Type}, {"PMCSCORINGPOINT", Int64.Type}}, "de-DE"),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"REFOBJECT ID"}, {{"LastVALIDFROMROW", each Table.Max(_, "PMCVALIDFROM"), type record}}),
    #"Expanded LastVALIDFROMROW" = Table.ExpandRecordColumn(#"Grouped Rows", "LastVALIDFROMROW", {"PMCVALIDFROM", "PMCRENTAMOUNT", "PMCSCORINGPOINT"}, {"PMCVALIDFROM", "PMCRENTAMOUNT", "PMCSCORINGPOINT"})
in
    #"Expanded LastVALIDFROMROW"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

2 REPLIES 2
PZUDGW
Helper I
Helper I

Works great!

 

Thanks for your help

Jimmy801
Community Champion
Community Champion

Hello @PZUDGW 

 

use Table.Group and within the group-function Table.Max to get your desired result. Here an example

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTI01jM01DMyADHBOFYHKmEBlzACY7iEqZ6hEUTCGIxBEk5AloGFnoGhnqElilEwCSOIBMIoJ4jlBsYQCahRsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"REFOBJECT ID" = _t, PMCVALIDFROM = _t, PMCRENTAMOUNT = _t, PMCSCORINGPOINT = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"REFOBJECT ID", type text}, {"PMCVALIDFROM", type date}, {"PMCRENTAMOUNT", Int64.Type}, {"PMCSCORINGPOINT", Int64.Type}}, "de-DE"),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"REFOBJECT ID"}, {{"LastVALIDFROMROW", each Table.Max(_, "PMCVALIDFROM"), type record}}),
    #"Expanded LastVALIDFROMROW" = Table.ExpandRecordColumn(#"Grouped Rows", "LastVALIDFROMROW", {"PMCVALIDFROM", "PMCRENTAMOUNT", "PMCSCORINGPOINT"}, {"PMCVALIDFROM", "PMCRENTAMOUNT", "PMCSCORINGPOINT"})
in
    #"Expanded LastVALIDFROMROW"

 

Copy paste this code to the advanced editor in a new blank query to see how the solution works.

If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
Kudoes are nice too

Have fun

Jimmy

View solution in original post

Helpful resources

Announcements
Power BI December 2021 Update_carousel 768x460.jpg

Check it Out!

Click here to read more about the December 2021 Updates!

User Group Leader Meeting January 768x460.png

Calling all User Group Leaders!

Don't miss the User Group Leader meetings on January, 24th & 25th, 2022.

Jan 2022 Dev Camp 768x460 copy.png

Power BI Dev Camp- January 27th, 2022

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors