Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hello,
I want to write a dax query, something using Rankx and windows function to get a table that will give me rank for each SKU'sales based on the category and region filters.
I have 4 tables linked to each(Sales table linked to Region by location code, Product by SKU and used to calculate the total sales.
I want to calculate the rank of each SKU by Product and Region and display then in ascending order.
Example:
Can anyone help me?
Thanks,
Ekta
@Zubair_Muhammad I saw that you solved a similar problem but it did not work for me. Could you tell me how to go about this one? Would be a great help!
Solved! Go to Solution.
Hi @Anonymous ,
Please have a try.
Create a measure.
Rank by Product and Region =
VAR CurrentSKU = Sales[SKU]
VAR CurrentProduct =
RELATED ( Product[Product] )
VAR CurrentRegion =
RELATED ( Region[Region] )
RETURN
RANKX (
FILTER (
ALL ( Sales ),
Sales[SKU] <> BLANK ()
&& RELATED ( Product[Product] ) = CurrentProduct
&& RELATED ( Region[Region] ) = CurrentRegion
),
CALCULATE ( SUM ( Sales[Sales] ) )
)
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Community Support Team _ Rongtie
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Anonymous ,
Please have a try.
Create a measure.
Rank by Product and Region =
VAR CurrentSKU = Sales[SKU]
VAR CurrentProduct =
RELATED ( Product[Product] )
VAR CurrentRegion =
RELATED ( Region[Region] )
RETURN
RANKX (
FILTER (
ALL ( Sales ),
Sales[SKU] <> BLANK ()
&& RELATED ( Product[Product] ) = CurrentProduct
&& RELATED ( Region[Region] ) = CurrentRegion
),
CALCULATE ( SUM ( Sales[Sales] ) )
)
How to Get Your Question Answered Quickly
If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .
Best Regards
Community Support Team _ Rongtie
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
hello, could you tell me which column are we referring to as Sales[Prodcut]?
Sales[Product] = SELECTEDVALUE(RankTable[Product]) && Sales[Region]
The sales table has SKU is linked to the product table with this SKU..
Got it, but it did not work, it's displaying 1 everywhere
To calculate the rank of each SKU's sales based on category and region filters in Power BI using DAX, you can use the RANKX function and FILTER to create the desired table. Here's a step-by-step guide:
Assuming you have the following tables:
And you want to calculate SKU rank by Product and Region, follow these steps:
RankTable = SUMMARIZE(CROSSJOIN(Product, Region), Product[Product], Region[Region])
This will create a table with all possible combinations of Product and Region.
SKU Rank =
RANKX(
FILTER(
ALL(Sales),
Sales[Product] = SELECTEDVALUE(RankTable[Product]) && Sales[Region] = SELECTEDVALUE(RankTable[Region])
),
[Total Sales]
)
In this measure:
Make sure that you have proper relationships set up between your tables, and the column names in the DAX formulas match your actual column names.
By following these steps, you should be able to calculate the rank of each SKU's sales based on the selected category (Product) and region filters in ascending order.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 9 | |
| 6 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 22 | |
| 14 | |
| 10 | |
| 6 | |
| 5 |