Forum Discussion
Dynamic change Ranking based on Dimension change
- 8 months ago
Hi Raju_KCS
You want a dynamic rank that:
Responds to the Dimension selected by the user (dynamic parameter).
Ranks by Measure (another dynamic parameter).
Works for single or multiple dimension selections.
Current DAX formula:Dynamic Rank = RANKX(
ALLSELECTED(Products[ProductName], Category[Category Name]),
[UC],
,
DESC
)Error:
> "All column arguments of the ALL/ALLNOBLANKROW/ALLSELECTED/REMOVEFILTERS function must be from the same table."
This happens because ALLSELECTED cannot take columns from multiple tables unless they have a proper relationship and you wrap them inside ALLSELECTED(VALUES(...)) or combine via UNION/SELECTCOLUMNS.
_
Use SELECTEDVALUE and SWITCH to pick the dimension
If you have a dynamic Dimension parameter, create a helper table with all dimension options:
Dimension Parameter =
DATATABLE(
"Dimension", STRING,
{
{"Product"},
{"Category"}
}
)Then create a Dynamic Rank measure:
Dynamic Rank =
VAR SelectedDimension = SELECTEDVALUE('Dimension Parameter'[Dimension])
RETURN
SWITCH(
TRUE(),
SelectedDimension = "Product",
RANKX(
ALLSELECTED(Products[ProductName]),
[UC],
,
DESC
),
SelectedDimension = "Category",
RANKX(
ALLSELECTED(Category[Category Name]),
[UC],
,
DESC
)
)✅ How it works:
Checks which dimension is selected.
Applies ALLSELECTED only to the column of that table.
RANKX works without errors.
Best regards
Nabha Ahmed
- 8 months ago
Hi Raju_KCS,
you can improve the solution with some practical adjustments. If your model allows, using a single unified dimension table for entities like Product and Category can simplify design and ranking, removing the need for complex unions and avoiding ALLSELECTED issues. For cases where users select multiple dimensions, create a virtual table with all relevant keys, add measure values, and rank accordingly to maintain consistency. It’s also helpful to add a tie-breaker to your ranking logic for equal values. Functions like ISINSCOPE or HASONEVALUE can help you detect the visual’s grain and adjust ranking. For better performance, calculate virtual tables once with variables and reuse them, and provide a fallback for when no dimension is selected to ensure predictable results.
Thank you.
Raju_KCS You will likely have better luck using the newer RANK function rather than RANKX. Sample data would be tremendously helpful here.
- Raju_KCS8 months agoFrequent Visitor
GeraldGEmerick - Please find the PBI file in below location, I don't have access to attach the files.
https://drive.google.com/drive/folders/1BmWv1rMfsqzuZYpLrwtZzKMvJiFz9ULf
Nabha-Ahmed - I have tried you're solution but no luck, could you please check the file.
Thank you for your valuable time spent on this thread.