Forum Discussion

Raju_KCS's avatar
Raju_KCS
Frequent Visitor
8 months ago
Solved

Dynamic change Ranking based on Dimension change

Hi Experts, I have created two dynamic parameters 1. Dimension and 2. Measure, based on selection chart will be shown. here my challenge is I have to show the ranking based on Dimension selection, ...
  • Nabha-Ahmed's avatar
    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 

     

  • v-sgandrathi's avatar
    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.