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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
arnabmit
Helper I
Helper I

Flag rows based on highest percentage

I want to create a new column "Flag" which will flag the highest percentage of the same Case ID. I am an M amateur and would really appreciate some help.

 

Screenshot 2022-06-08 103721.png

 

 

 

 

 

 

 

 

 

 

The formula that I used in excel was this:

=IF(C2=MAXIFS($C$2:$C$7,$A$2:$A$7,A2),1,0)

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @arnabmit ;

You could group by the Case ID column then add a condition column.

1. group by Case ID column.

vyalanwumsft_0-1654848060038.png

2.expand the table.

vyalanwumsft_1-1654848088481.png

3. add a condition column.

vyalanwumsft_2-1654848122341.png

4.delete the Max column.and The final output is shown below:

vyalanwumsft_3-1654848233489.png

In additonal , M language like below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRcgRiQwNVpVgdmIgTEFtCRUyMDKFqzFBEnIHYBCpiZA7TZYwi4gLE5lARY0szqC5zU2QRkBojkEgsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Case ID" = _t, Name = _t, Percent = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Case ID", Int64.Type}, {"Name", type text}, {"Percent", Percentage.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Case ID"}, {{"Max", each List.Max([Percent]), type nullable number}, {"a", each _, type table [Case ID=nullable number, Name=nullable text, Percent=nullable number]}}),
    #"Expanded a" = Table.ExpandTableColumn(#"Grouped Rows", "a", {"Name", "Percent"}, {"a.Name", "a.Percent"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded a", "Flag", each if [a.Percent] = [Max] then 1 else 0),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Max"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"a.Percent", "Percent"}, {"a.Name", "Name"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Percent", Percentage.Type}})
in
    #"Changed Type1"

 
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @arnabmit ;

You could group by the Case ID column then add a condition column.

1. group by Case ID column.

vyalanwumsft_0-1654848060038.png

2.expand the table.

vyalanwumsft_1-1654848088481.png

3. add a condition column.

vyalanwumsft_2-1654848122341.png

4.delete the Max column.and The final output is shown below:

vyalanwumsft_3-1654848233489.png

In additonal , M language like below:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVtJRcgRiQwNVpVgdmIgTEFtCRUyMDKFqzFBEnIHYBCpiZA7TZYwi4gLE5lARY0szqC5zU2QRkBojkEgsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Case ID" = _t, Name = _t, Percent = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Case ID", Int64.Type}, {"Name", type text}, {"Percent", Percentage.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Case ID"}, {{"Max", each List.Max([Percent]), type nullable number}, {"a", each _, type table [Case ID=nullable number, Name=nullable text, Percent=nullable number]}}),
    #"Expanded a" = Table.ExpandTableColumn(#"Grouped Rows", "a", {"Name", "Percent"}, {"a.Name", "a.Percent"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded a", "Flag", each if [a.Percent] = [Max] then 1 else 0),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"Max"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"a.Percent", "Percent"}, {"a.Name", "Name"}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Renamed Columns",{{"Percent", Percentage.Type}})
in
    #"Changed Type1"

 
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you so much! This is perfect!

wdx223_Daniel
Super User
Super User

NewStep=let a=Table.Buffer(Table.Group(PreviousStepName,{"Case ID","Name"},{"n",each List.Max([Percent])})) in Table.AddColumn(PreviousStepName,"Flag",each Byte.From([Percent]=a{[Case ID=[Case ID],Name=[Name]]}[n]))

Thanks a lot for your reply!
It gave me all 1 in the Flag column. Did I do something wrong?

 

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Case ID", Int64.Type}, {"Name", type text}, {"Percent", type number}}),
#"Add Column" = let a=Table.Buffer(Table.Group(#"Changed Type",{"Case ID","Name"},{"n",each List.Max([Percent])})) in Table.AddColumn(#"Changed Type","Flag",each Byte.From([Percent]=a{[Case ID=[Case ID],Name=[Name]]}[n]))
in
#"Add Column"

 

arnabmit_0-1654680396475.png

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors