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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
newpbiuser01
Helper IV
Helper IV

Ranking over multiple categories

Hello,

 

I have a table that breaks down sales for different stores to multiple categories/subcategories. I am trying to find the top two category/subcagories for each store by spend and also calculate the % of spend over each category.

 

If it was just the stores, I'd do Group By in Power Query, and do sum of spend, sort it in descending order and then create an index column. But I'm not sure how to do it with the nested categories/subcategories within the Stores. Also I'm not sure if the % of Spend over each store is possible in power query or do I do it in DAX. My table is as follows: 

 

Main Table: 

StoreCategoriesSubcategorySpend
AClothingMen47
AClothingWomen26
AShoesKids75
AHousewaresDishes17
BBooksFiction64
BStationaryPaper72
BBagsHandbags95
BBaby ItemsToys22
CBakery ItemsBread31
CBeveragesWater63
CHousewaresCandles22
CProduceFruits74
CProduceVegetables70
DBakery ItemsCakes54
DProduceFruits81
DProduceVegetables29
DBakery ItemsBread52
EBooksFiction28
EStationaryPens11
EStationaryPencils57
EStationaryMarkers38
EStationaryPaper99
FProduceFruits83
FDairyMillk40
FDairyCheese79
FProduceVegetables89

 

I'd like to first calculate the rank: 

StoreCategoriesSucategorySpendRank
AClothingMen472
AClothingWomen263
AShoesKids751
AHousewaresDishes174
BBooksFiction643
BStationaryPaper722
BBagsHandbags951
BBaby ItemsToys224
CBakery ItemsBread314
CBeveragesWater633
CHousewaresCandles225
CProduceFruits741
CProduceVegetables702
DBakery ItemsCakes542
DProduceFruits811
DProduceVegetables294
DBakery ItemsBread523
EBooksFiction284
EStationaryPens115
EStationaryPencils572
EStationaryMarkers383
EStationaryPaper991
FProduceFruits832
FDairyMillk404
FDairyCheese793
FProduceVegetables891

 

And the final result would be as follows: 

StoreCategorySubcategorySpendRank% of Spend
AShoesKids75145%
AClothingMen47228%
BBagsHandbags95138%
BStationaryPaper72228%
CProduceFruits74128%
CProduceVegetables70227%
DProduceFruits81138%
DBakery ItemsCakes54225%
EStationaryPaper99142%
EStationaryPencils57224%
FProduceVegetables89131%
FProduceFruits83229%

 

Would anyone know how I could do this? I'd really appreciate any help. 

 

Thank you!

1 ACCEPTED SOLUTION
ddpl
Solution Sage
Solution Sage

@newpbiuser01 

 

Create 2 calculated column as below...

 

Rank = RANKX(FILTER('Table', 'Table'[Store] = EARLIER('Table'[Store])), 'Table'[Spend])
 
% Spent = 
DIVIDE(
    'Table'[Spend],
    SUMX(FILTER('Table', 'Table'[Store] = EARLIER('Table'[Store])), 'Table'[Spend])
)
 
bin01.png
 
bin02.png

View solution in original post

2 REPLIES 2
ddpl
Solution Sage
Solution Sage

@newpbiuser01 

 

Create 2 calculated column as below...

 

Rank = RANKX(FILTER('Table', 'Table'[Store] = EARLIER('Table'[Store])), 'Table'[Spend])
 
% Spent = 
DIVIDE(
    'Table'[Spend],
    SUMX(FILTER('Table', 'Table'[Store] = EARLIER('Table'[Store])), 'Table'[Spend])
)
 
bin01.png
 
bin02.png

Thanks @ddpl! This worked beautifully!

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.