cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PowerWhy
Helper III
Helper III

How to filter by the maximum value in a field?

Hello,

 

Say I had a table of transactions, and there was a field with fiscal year. Please can you tell me how to only return records who's fiscal year is equal to the maximum in that column (i.e. the latest fiscal year)

 

Thank you,

 

PW

1 ACCEPTED SOLUTION
Payeras_BI
Solution Sage
Solution Sage

Hi @PowerWhy ,

A possible solution:

Payeras_BI_0-1683626934787.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMlCK1UFlGMIYRjCGMRIjFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Fiscal Year" = _t]),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Fiscal Year] = List.Max(Source[Fiscal Year])))
in
    #"Filtered Rows"

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

View solution in original post

2 REPLIES 2
v-stephen-msft
Community Support
Community Support

Hi @PowerWhy ,

 

You could try the Group By in Power Query.

Here're the steps.

1.Load the table of transactions into Power Query.

2.Group the table by the fiscal year field.

3.Add an aggregation step to find the maximum value of the fiscal year field.

4.Merge the maximum value back into the original table using a left outer join.

5.Filter the table to only include rows where the fiscal year field is equal to the maximum value.

 

Reference: How to GROUP BY or summarize rows - Power Query | Microsoft Learn

 

   

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

Payeras_BI
Solution Sage
Solution Sage

Hi @PowerWhy ,

A possible solution:

Payeras_BI_0-1683626934787.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMlCK1UFlGMIYRjCGMRIjFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Fiscal Year" = _t]),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Fiscal Year] = List.Max(Source[Fiscal Year])))
in
    #"Filtered Rows"

 

If this post answered your question, please mark it as a solution to help other users find useful content.
Kudos are another nice way to acknowledge those who tried to help you.

J. Payeras
Mallorca, Spain

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors