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
ASG25
Regular Visitor

How to add two separate Rank Column based on two criteria?

Hi,
In below table, I need value base ranking by country & cust state wise in power query... 

Customer No.Customer NameProduct CodeProduct DescriptionValueCountyCust StateCountry RankState Rank
98717232Abishek Enterprises3457652IMBUSH 10x4X250 ML238339INMP  
98742618NATARAJA STORES3457144CARATE 4x25X100 ML 2034283INMP  
98742618NATARAJA STORES3493457FANTIS 10X1 L     324930INMP  
98743861BALAJI TRADER3437662CARATE 2x5X1 L     349834INGJ  
98743861BALAJI TRADER3457646IMBUSH 5x2X1 L    3487INGJ  
98718113Meenashi Services3459175SIFLEX 25X400 ML 346837INGJ  
98735175BRUNA Co.Pvt. Ltd3469469AMISTAR TOP 20X500 ML56089INTG  
98735178amarapuri Enterprises3457361ABION 40X250 ML  349837INTG  
98735178amarapuri Enterprises3457362ABION 20X500 ML  546089INTG  
98735178amarapuri Enterprises3457363ABION 10X1 L     2465322INTG  
98735178amarapuri Enterprises3457653IMBUSH 25x4X100 ML3095867INTG  
98744355PAVITHRA AGENCY3457483ARAIFIT 50 EC 20x500 ML4985495INTG  
98744355PAVITHRA AGENCY3457579ABION 2X5 L      348734INTG  

 

I have tried for solution by Grouping option in power query result shows only country ranking.

 

Just for Example:- below First 4 Column is summarized with Pivot & then last 2 column added manually

Customer No.Customer NameCust State ValueCountry RankState Rank
98735178amarapuri EnterprisesTG645711511
98744355PAVITHRA AGENCYTG533422922
98742618NATARAJA STORESMP235921331
98743861BALAJI TRADERGJ35332141
98718113Meenashi ServicesGJ34683752
98717232Abishek EnterprisesMP23833962
98735175BRUNA Co.Pvt. LtdTG5608973




 

2 ACCEPTED SOLUTIONS
ThxAlot
Super User
Super User

ThxAlot_0-1710764941662.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



View solution in original post

dufoq3
Super User
Super User

Hi @ASG25, it is also possible in Power Query, but it is not the fastest one...

 

Result:

dufoq3_0-1710775162627.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZNba9tAEIX/yuLnEPYys1o9rl3ZWSPJRtoElZAHtxFEhKZBdoN+fmcVXRJiKEmFEMMM+zE65+zt7SI2kYikkouLhf3RHB/qR5Y8ner2uW2O9ZG6CjDSGOYuW16XV0zwDiqJnGUpNaUySsVhmtMn2y/uLnooSC0MdXLrbWG3lpV+VyTlABQAVK1o4hMGncRK8ABkgcgVSKM+h4wDlaq1zb0racdKsJSFJ4wlzfkZoDJaUGdpU7t1zBf2W1L0OBVpLecNZYfveBAbBSNvs/03jyQEPUuInRx5/dhEH2HCCBFEyOr66XB8aFhZty/Nz9GTWERIVenWaVIxEhAmARVoo84QFb6eWRbXuWWr35f7l9MlS0/3r2diekMKMleSvszv9kzyCvlgNGpuJp/95i00mHL4dWgPz3/a5kx8VK+KXbpdzoAP2ZmVjL5KlRN1WrSnIvzPrmqivk+RBI1Kyq9h6ehsv0S6QWIUVvEYjT4jAoDC4Nfe3jh/VVhmN0m++j4Qob8ilE+3dp6RpMmKZOgmv0hZhBg/i8UonlWtcPj9MaZz6gPv7i8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Customer No." = _t, #"Customer Name" = _t, #"Product Code" = _t, #"Product Description" = _t, Value = _t, Country = _t, #"Cust State" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Value", type number}}),
    GroupedRows1 = Table.Group(ChangedType, {"Customer No.", "Customer Name", "Country", "Cust State"}, {{"Value", each List.Sum([Value]), type number}}),
    // Added State Rank inside [All] tables.
    GroupedRows2 = Table.Group(GroupedRows1, {"Country", "Cust State"}, {{"All", each Table.AddIndexColumn(Table.Sort(_, {{"Value", Order.Descending}}), "State Rank", 1, 1, Int64.Type), type table}}),
    CombinedAll1 = Table.Combine(GroupedRows2[All]),
    // Added Country Rank inside [All] tables.
    GroupedRows3 = Table.Group(CombinedAll1, {"Country"}, {{"All", each Table.AddIndexColumn(Table.Sort(_, {{"Value", Order.Descending}}), "Country Rank", 1, 1, Int64.Type), type table}}),
    CombinedAll2 = Table.Combine(GroupedRows3[All])
in
    CombinedAll2

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

2 REPLIES 2
dufoq3
Super User
Super User

Hi @ASG25, it is also possible in Power Query, but it is not the fastest one...

 

Result:

dufoq3_0-1710775162627.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pZNba9tAEIX/yuLnEPYys1o9rl3ZWSPJRtoElZAHtxFEhKZBdoN+fmcVXRJiKEmFEMMM+zE65+zt7SI2kYikkouLhf3RHB/qR5Y8ner2uW2O9ZG6CjDSGOYuW16XV0zwDiqJnGUpNaUySsVhmtMn2y/uLnooSC0MdXLrbWG3lpV+VyTlABQAVK1o4hMGncRK8ABkgcgVSKM+h4wDlaq1zb0racdKsJSFJ4wlzfkZoDJaUGdpU7t1zBf2W1L0OBVpLecNZYfveBAbBSNvs/03jyQEPUuInRx5/dhEH2HCCBFEyOr66XB8aFhZty/Nz9GTWERIVenWaVIxEhAmARVoo84QFb6eWRbXuWWr35f7l9MlS0/3r2diekMKMleSvszv9kzyCvlgNGpuJp/95i00mHL4dWgPz3/a5kx8VK+KXbpdzoAP2ZmVjL5KlRN1WrSnIvzPrmqivk+RBI1Kyq9h6ehsv0S6QWIUVvEYjT4jAoDC4Nfe3jh/VVhmN0m++j4Qob8ilE+3dp6RpMmKZOgmv0hZhBg/i8UonlWtcPj9MaZz6gPv7i8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Customer No." = _t, #"Customer Name" = _t, #"Product Code" = _t, #"Product Description" = _t, Value = _t, Country = _t, #"Cust State" = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Value", type number}}),
    GroupedRows1 = Table.Group(ChangedType, {"Customer No.", "Customer Name", "Country", "Cust State"}, {{"Value", each List.Sum([Value]), type number}}),
    // Added State Rank inside [All] tables.
    GroupedRows2 = Table.Group(GroupedRows1, {"Country", "Cust State"}, {{"All", each Table.AddIndexColumn(Table.Sort(_, {{"Value", Order.Descending}}), "State Rank", 1, 1, Int64.Type), type table}}),
    CombinedAll1 = Table.Combine(GroupedRows2[All]),
    // Added Country Rank inside [All] tables.
    GroupedRows3 = Table.Group(CombinedAll1, {"Country"}, {{"All", each Table.AddIndexColumn(Table.Sort(_, {{"Value", Order.Descending}}), "Country Rank", 1, 1, Int64.Type), type table}}),
    CombinedAll2 = Table.Combine(GroupedRows3[All])
in
    CombinedAll2

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

ThxAlot
Super User
Super User

ThxAlot_0-1710764941662.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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