Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

calculated column is not working as excepted.

LegendCategory =
SWITCH(
TRUE(),
SELECTEDVALUE(Reporter[Reporter Order]) = 0, 'DMT_GTA W_DMT_GTA_V_GTA_FCST_TON'[Import Zone],
SELECTEDVALUE(Reporter[Reporter Order]) = 1, 'DMT_GTA W_DMT_GTA_V_GTA_FCST_TON'[Export Country/Territory],
SELECTEDVALUE(Reporter[Reporter Order]) = 2, 'DMT_GTA W_DMT_GTA_V_GTA_FCST_TON'[Import Zone],
SELECTEDVALUE(Reporter[Reporter Order]) = 3, 'DMT_GTA W_DMT_GTA_V_GTA_FCST_TON'[Export Zone],
"Please select a value"
)
It's giving back only Import Zone only. see when reporter order is 1 it's giving only import zone. And same for order 2, order 3 also.

 

  • danextian's avatar
    danextian
    1 year ago

    Hi Anonymous Measures cannot be used as legends as they don't have row context. They are evaluated based on the dimensions added to a viz and/or an external filter like from  a slicer. That aside, it seems that you are trying to switch to different columns based on the selected report order. This is a good use case for field parameters as others have already suggested. You can just use the order column generated when creating a field parameter table in a slicer.

     

     

     

6 Replies

  • Dangar332's avatar
    Dangar332
    Icon for Resident Rockstar rankResident Rockstar

    Hello , Anonymous 

    calculated column does not behave dynamically Like Measure, you need to write measure instead of Calculated column.


    Best Regards,
    Dangar

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.



  • Anonymous's avatar
    Anonymous
    Not applicable

    I know but measure can't drag into leagend.

    • danextian's avatar
      danextian
      Icon for Super User rankSuper User

      Hi Anonymous Measures cannot be used as legends as they don't have row context. They are evaluated based on the dimensions added to a viz and/or an external filter like from  a slicer. That aside, it seems that you are trying to switch to different columns based on the selected report order. This is a good use case for field parameters as others have already suggested. You can just use the order column generated when creating a field parameter table in a slicer.

       

       

       

    • Dangar332's avatar
      Dangar332
      Icon for Resident Rockstar rankResident Rockstar

      Anonymous  can you explain Exact Requirment, where you want to use Legend.

      • Anonymous's avatar
        Anonymous
        Not applicable


        This is calculated coumn i used here. but when measure is not dragging into legend.

  • Hi Anonymous 

     

    The problem occurs because you're using SELECTEDVALUE in a calculated column. In the context of a calculated column, SELECTEDVALUE returns the value of the column for the current row during data refresh—not the value selected by the user in a slicer or filter. This means the calculated column cannot respond to user interactions in the report.

    As a result, your SWITCH function always evaluates the same condition for each row, leading to the same output (Import Zone) for all cases.

    Solution:

    To make your LegendCategory change dynamically based on user selection, you need to create a measure instead of a calculated column. Measures are calculated at query time and can respond to slicers and filters in your report.

    Revised Measure:

     

    LegendCategory = 
    SWITCH(
        TRUE(),
        SELECTEDVALUE(Reporter[Reporter Order]) = 0, MAX('DMT_GTA W_DMT_GTA_V_GTA_FCST_TON'[Import Zone]),
        SELECTEDVALUE(Reporter[Reporter Order]) = 1, MAX('DMT_GTA W_DMT_GTA_V_GTA_FCST_TON'[Export Country/Territory]),
        SELECTEDVALUE(Reporter[Reporter Order]) = 2, MAX('DMT_GTA W_DMT_GTA_V_GTA_FCST_TON'[Import Zone]),
        SELECTEDVALUE(Reporter[Reporter Order]) = 3, MAX('DMT_GTA W_DMT_GTA_V_GTA_FCST_TON'[Export Zone]),
        "Please select a value"
    )
    

     

    Alternate Approach if Column is Required:

    If you must use a column (e.g., for chart axes or legends), you can:

    Create Multiple Calculated Columns:

    Create separate calculated columns for each possible Reporter Order value.
    Use visual-level filters or bookmarks to show/hide visuals based on user selection.
    Use Field Parameters (Power BI Feature):

    Field parameters allow users to change the dimensions used in visuals dynamically.
    This feature can simulate changing the column used based on user selection.

     

    If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

    Appreciate your Kudos!! 

     

    LinkedIn|Twitter|Blog |YouTube