Forum Discussion

newbie9's avatar
newbie9
Helper I
2 years ago
Solved

selectedvalue & switch

hi All,

 

I like to know the difference between 

switch( selectedvalue('table'[game])

.... some conditons....

)

 

vs

switch( 'table'[game]

.... some conditions...

)

 

what's the difference in using selectedvalue & not using selectedvalue?

 

  •  

    In Power BI, the SELECTEDVALUE function and referencing a column directly can serve different purposes, and understanding when to use each depends on your specific requirements and the context of your calculations. Let's break down the differences between the two:

    1. Using SELECTEDVALUE:

      • SELECTEDVALUE is a DAX (Data Analysis Expressions) function in Power BI that is primarily used in measures or calculated columns.
      • It is typically used when you want to retrieve the single value selected in a slicer or filter context. For example, if you have a slicer for a game and want to perform calculations based on the selected game, you would use SELECTEDVALUE.
      • It's useful when you want to handle scenarios where there may be multiple selections and you want to ensure that only a single value is considered.
      • It helps avoid errors that might occur when there are multiple selections.

      Example:

    Measure =
    SWITCH(
    SELECTEDVALUE('table'[game]),
    "Game A", ...,
    "Game B", ...,
    "Game C", ...
    )

     

    Referencing the Column Directly:

    • When you reference a column directly like 'table'[game], you are not considering any filter or slicer context. You are working with the entire column of values in the 'game' column without regard to any selections or filters applied in your report.
    • This approach is useful when you want to aggregate or perform calculations on all the values in the column, regardless of the current selection. It's often used in calculated columns or in cases where you need to perform calculations on the entire dataset.

    Example:

     

    Measure =
    SWITCH(
    'table'[game],
    "Game A", ...,
    "Game B", ...,
    "Game C", ...
    )

     

    In summary, the key difference is that SELECTEDVALUE is used to consider the current user-selected value in a slicer or filter context, while referencing the column directly ('table'[game]) ignores the context and works with all values in the column. The choice between the two depends on your specific calculation requirements and whether you need to consider user selections in your calculations.

2 Replies

  • 123abc's avatar
    123abc
    Community Champion

     

    In Power BI, the SELECTEDVALUE function and referencing a column directly can serve different purposes, and understanding when to use each depends on your specific requirements and the context of your calculations. Let's break down the differences between the two:

    1. Using SELECTEDVALUE:

      • SELECTEDVALUE is a DAX (Data Analysis Expressions) function in Power BI that is primarily used in measures or calculated columns.
      • It is typically used when you want to retrieve the single value selected in a slicer or filter context. For example, if you have a slicer for a game and want to perform calculations based on the selected game, you would use SELECTEDVALUE.
      • It's useful when you want to handle scenarios where there may be multiple selections and you want to ensure that only a single value is considered.
      • It helps avoid errors that might occur when there are multiple selections.

      Example:

    Measure =
    SWITCH(
    SELECTEDVALUE('table'[game]),
    "Game A", ...,
    "Game B", ...,
    "Game C", ...
    )

     

    Referencing the Column Directly:

    • When you reference a column directly like 'table'[game], you are not considering any filter or slicer context. You are working with the entire column of values in the 'game' column without regard to any selections or filters applied in your report.
    • This approach is useful when you want to aggregate or perform calculations on all the values in the column, regardless of the current selection. It's often used in calculated columns or in cases where you need to perform calculations on the entire dataset.

    Example:

     

    Measure =
    SWITCH(
    'table'[game],
    "Game A", ...,
    "Game B", ...,
    "Game C", ...
    )

     

    In summary, the key difference is that SELECTEDVALUE is used to consider the current user-selected value in a slicer or filter context, while referencing the column directly ('table'[game]) ignores the context and works with all values in the column. The choice between the two depends on your specific calculation requirements and whether you need to consider user selections in your calculations.