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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
sudershan
Regular Visitor

Row with min value within a category

Hi,

 

I have the following data:

S.No.Txn DateOpening Bal.Txn Amount
101-Jan-20221001000
201-Jan-20221100500
302-Jan-20221600800
402-Jan-20222400-300
503-Jan-20222100750

 

I need to get the row with min of S.No. for each category of Txn Date.  Or I need to get the Opening Bal. for each Txn Date in a separate query.

I tried Group By by Txn Date with Min of S.No.  but this does not give me the Opening Bal.

Thanks

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLU9UrM0zUyAjENDCCkgVKsTrSSEZosRNoUKmsMZBshyZqBZS2gsiaoskYmYFldY6i0KZBjjCQNMdrcFCgbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"S.No." = _t, #"Txn Date" = _t, #"Opening Bal." = _t, #"Txn Amount" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"S.No.", Int64.Type}, {"Txn Date", type date}, {"Opening Bal.", Int64.Type}, {"Txn Amount", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Txn Date"}, {{"S.No.", each List.Min([#"S.No."]), type nullable number}}),
    #"Merged Queries" = Table.NestedJoin(#"Grouped Rows", {"S.No."}, #"Changed Type", {"S.No."}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"Opening Bal."}, {"Opening Bal."})
in
    #"Expanded Grouped Rows"

 👍 It's been a pleasure to help you | Help Hours: 11 AM to 9 PM (UTC+05:30)

How to get your questions answered quickly -- How to provide sample data

View solution in original post

1 REPLY 1
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately. If you have columns other than these, then delete Changed type step and do a Changed type for complete table from UI again)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTLU9UrM0zUyAjENDCCkgVKsTrSSEZosRNoUKmsMZBshyZqBZS2gsiaoskYmYFldY6i0KZBjjCQNMdrcFCgbCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"S.No." = _t, #"Txn Date" = _t, #"Opening Bal." = _t, #"Txn Amount" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"S.No.", Int64.Type}, {"Txn Date", type date}, {"Opening Bal.", Int64.Type}, {"Txn Amount", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Txn Date"}, {{"S.No.", each List.Min([#"S.No."]), type nullable number}}),
    #"Merged Queries" = Table.NestedJoin(#"Grouped Rows", {"S.No."}, #"Changed Type", {"S.No."}, "Grouped Rows", JoinKind.LeftOuter),
    #"Expanded Grouped Rows" = Table.ExpandTableColumn(#"Merged Queries", "Grouped Rows", {"Opening Bal."}, {"Opening Bal."})
in
    #"Expanded Grouped Rows"

 👍 It's been a pleasure to help you | Help Hours: 11 AM to 9 PM (UTC+05:30)

How to get your questions answered quickly -- How to provide sample data

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors