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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
harsha_9640
Frequent Visitor

How do i find maximum values from a column with respect to other column data

Migrating bobj report to power bi. In bobj I have a calculation as = Max(IF([Replicate = 1] Then ([Result])) In ([Batch ID])

 

Sample Data

 

Batch IDResult Value Replicate
8172.931
8172.852
8213.021
8212.942

 

Expected result


Bach IDResult ValueReplicateValue
8172.9312.93
8172.8522.93
8213.0213.02
8212.9423.02

 

@PowerBI 

@lbendlin 

@amitchandak 

@Ritaf1983 

@Idrissshatila 

@OwenAuger 

2 ACCEPTED SOLUTIONS
Ritaf1983
Super User
Super User

Hi @harsha_9640 

If you want a Dax solution, you can add a calculated column with the formula:

max_by_id = CALCULATE(max('Table'[Result Value]), ALLEXCEPT('Table','Table'[Batch ID]))
Ritaf1983_0-1700250106942.png

Pbix is attached 

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

Hi @harsha_9640 

If you want the values to change according to the slicers / filters selections you cant use calculated columns and need to create measures.

Ritaf1983_0-1700464397888.pngRitaf1983_1-1700464432185.png

 

Ritaf1983_3-1700464496846.png

 

The updated pbix is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

6 REPLIES 6
Ritaf1983
Super User
Super User

Hi @harsha_9640 

If you want a Dax solution, you can add a calculated column with the formula:

max_by_id = CALCULATE(max('Table'[Result Value]), ALLEXCEPT('Table','Table'[Batch ID]))
Ritaf1983_0-1700250106942.png

Pbix is attached 

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Sample Data

 

Batch IDResult Value Replicate
8172.931
8172.852
8213.021
8212.942

 

Expected result


Bach IDResult ValueReplicateMax_Value

Min_Value

 

Range

8172.9312.932.850.08
8172.8522.932.850.08
8213.0213.022.940.08
8212.9423.022.940.08

@Rita Te approach is correct but the result is not expected for my data. I tink you didn't use the replicate filter. So, when Replicate is 1 the Max_value should be 2.93 and 3.02 and when it is 2 the Min_Value should be 2.85 and 2.94. And we need to calculate the range i,e Range =  Max_value - Min_Value. Please suggest this approach of the dax.

Hi @harsha_9640 

If you want the values to change according to the slicers / filters selections you cant use calculated columns and need to create measures.

Ritaf1983_0-1700464397888.pngRitaf1983_1-1700464432185.png

 

Ritaf1983_3-1700464496846.png

 

The updated pbix is attached

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

Thanks for the solution. That worked.

Happy to help.

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile
lbendlin
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsjA0V9JRMtKzNAZShkqxOgghC1MQBREyMgSyjfUMjBCqwEJAjSYQVbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Batch ID" = _t, #"Result Value" = _t, #" Replicate" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Batch ID", Int64.Type}, {"Result Value", type number}, {" Replicate", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Batch ID"}, {{"Value", each List.Max([Result Value]), type nullable number}, {"Rows", each _, type table [Batch ID=nullable number, Result Value=nullable number, #" Replicate"=nullable number]}}),
    #"Expanded Rows" = Table.ExpandTableColumn(#"Grouped Rows", "Rows", {"Result Value", " Replicate"}, {"Result Value", " Replicate"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Expanded Rows",{"Batch ID", "Result Value", " Replicate", "Value"})
in
    #"Reordered Columns"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done".

Helpful resources

Announcements
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 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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