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
pbi_throw_away
Frequent Visitor

AddRankColumn only when a condition exists

By customer ID, I am trying to rank order records but only when columnA = true. If not true/false, then the value can be 0.

 

Is this possible using Table.AddRankColumn?

 

If not, is there a way to rank order records only when the value is true?

 

Thank you

1 REPLY 1
m_dekorte
Super User
Super User

Hi @pbi_throw_away 

 

Give something like this a go, where you group by customer and columnA to conditionally add a rank

Copy this example into a new blank query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ZZE7EsIwDETv4jpF9LOkkgIqKj5VJve/BtgGJmYLN2/W8ltr28rj9jyXpdT3kdBa9uXHqDFTPzJubGU5MhksgTFNOW3M1/HG5XS9N+gNivIx2GVIpoHRBzJBTilxYFWCy+krGApVaPd3tzNxbKys0E6NJplhnQEDgxQExQ0Y0fxd1l+pk81oTGhtgblkhh1rJDBXzEm1SWY04YrfEIaLjymXvV36NLAH42P9hX3LaxhC07f3/gI=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ColumnA = _t, #"Customer ID" = _t, Order = _t]),
    GroupRows = Table.Group(Source, {"ColumnA", "Customer ID"}, {{"t", each if List.First([ColumnA]) = "TRUE" then Table.AddRankColumn( _, "Rank", {"Order", Order.Descending}) else Table.AddColumn( _, "Rank", each 0 ), type table [ColumnA=nullable text, Customer ID=nullable text, Order=nullable text, Rank=number]}}),
    AddCustOrderRank = Table.ExpandTableColumn(GroupRows, "t", {"Order", "Rank"}, {"Order", "Customer Order Rank"})
in
    AddCustOrderRank

 

Ps. Please mark this answer as solution when it helped you to resolve your question, thanks!

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