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

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

Reply
cathoms
Responsive Resident
Responsive Resident

Return one row per account number based on Max value of a column

Good afternoon!

I have a table as follows:

 

HARLineNBRDRGWtGMLOS
111.27958.2
211.29355.3
310.88233.6
410.97353.8
420.97353.8
510.79952.9
520.79952.9
612.52685.9
621.38415.62
631.38415.62
641.38415.62
710.54592.5
811.21973.4

 

I need to filter this so that I have a table with one row per hospital account (HAR) using the max LineNBR for each HAR. That is, I want the following:

 

HARLineNBRDRGWtGMLOS
111.27958.2
211.29355.3
310.88233.6
420.97353.8
520.79952.9
641.38415.62
710.54592.5
811.21973.4

 

What is the best way to accomplish this? I've tried group by and either end up with just one row total for the maximum LineNBR (in this case 4) or one row per line number. My attempted solutions come from the following posts: Solved: Return only rows with max value from specific colu... - Microsoft Fabric Community and Solved: How to filter by max value in power query - Microsoft Fabric Community.

 

If it helps, in SQL that would look something like this:

 

 

SELECT
     HAR,
     DRGWt,
     GMLOS,
     MAX (LineNBR) MaxLine
FROM EDW.Billing.HospitalAccountDRG
GROUP BY
     HAR,
     DRGWt,
     GMLOS

 

 

p.s. Ideally, this would be foldable so that I can set up incremental refresh.

 

 

1 ACCEPTED SOLUTION
jgeddes
Super User
Super User

You can try this...
Group by HAR, select the row from the resulting nested table that has the max LineNBR and then expand the nested table.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddBBDgQhCATAv3iekLUBgbcY//+N3WEmeHEPJppKh8Y5W2/XcwgW+rs4oa1rNmwIvkGJE/iFD7njfjCNBCkIywSTF+AEWgmLHA6KApxgvAmQYni22pCViV16wkAJ/xU5ilUxFY1nXoLvX+lhuYq0tb4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [HAR = _t, LineNBR = _t, DRGWt = _t, GMLOS = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"HAR", Int64.Type}, {"LineNBR", Int64.Type}, {"DRGWt", type number}, {"GMLOS", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"HAR"}, {{"_nestedTable", each _, type table [HAR=nullable number, LineNBR=nullable number, DRGWt=nullable number, GMLOS=nullable number]}}),
    Custom1 = Table.TransformColumns(#"Grouped Rows", {{"_nestedTable", each Table.SelectRows(_, (x)=> x[LineNBR] = List.Max([LineNBR])), type table [HAR=nullable number, LineNBR=nullable number, DRGWt=nullable number, GMLOS=nullable number]}}),
    #"Expanded _nestedTable" = Table.ExpandTableColumn(Custom1, "_nestedTable", {"LineNBR", "DRGWt", "GMLOS"}, {"LineNBR", "DRGWt", "GMLOS"})
in
    #"Expanded _nestedTable"




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
jgeddes
Super User
Super User

You can try this...
Group by HAR, select the row from the resulting nested table that has the max LineNBR and then expand the nested table.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddBBDgQhCATAv3iekLUBgbcY//+N3WEmeHEPJppKh8Y5W2/XcwgW+rs4oa1rNmwIvkGJE/iFD7njfjCNBCkIywSTF+AEWgmLHA6KApxgvAmQYni22pCViV16wkAJ/xU5ilUxFY1nXoLvX+lhuYq0tb4=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [HAR = _t, LineNBR = _t, DRGWt = _t, GMLOS = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"HAR", Int64.Type}, {"LineNBR", Int64.Type}, {"DRGWt", type number}, {"GMLOS", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"HAR"}, {{"_nestedTable", each _, type table [HAR=nullable number, LineNBR=nullable number, DRGWt=nullable number, GMLOS=nullable number]}}),
    Custom1 = Table.TransformColumns(#"Grouped Rows", {{"_nestedTable", each Table.SelectRows(_, (x)=> x[LineNBR] = List.Max([LineNBR])), type table [HAR=nullable number, LineNBR=nullable number, DRGWt=nullable number, GMLOS=nullable number]}}),
    #"Expanded _nestedTable" = Table.ExpandTableColumn(Custom1, "_nestedTable", {"LineNBR", "DRGWt", "GMLOS"}, {"LineNBR", "DRGWt", "GMLOS"})
in
    #"Expanded _nestedTable"




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

Proud to be a Super User!





cathoms
Responsive Resident
Responsive Resident

That seems to have worked. Thanks much!

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Kudoed Authors