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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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