Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
newbie9
Helper I
Helper I

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?

 

1 ACCEPTED SOLUTION
123abc
Community Champion
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.

View solution in original post

2 REPLIES 2
123abc
Community Champion
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.

Thanks for the reply

it was helpful

can you help me with the below one too?

https://community.fabric.microsoft.com/t5/Desktop/count-of-columns/m-p/3679253

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.