How to Get the Value of the Selected Row in the Table to a Var in DAX

Have you ever wondered how to retrieve the value of the selected row in a table, and as well store it as a VAR in DAX?

In this article, I will explain the process of how you use the SELECTEDVALUE function in DAX to retrieve the value of the selected row in a table.

Read to learn more.

Introduction

To get the value of a selected row in a table, the first thing to do is to select the row you want to get its value in a table, by inputting the following syntax:

SELECTEDVALUE(table_name[column_name])

Where SELECTEDVALUE is the DAX function, table_name is the name of the table, and “column_name” is the name of the column whose value you want to get.

For example, if you have a table called Profit and you want to get the value of the selected row in the Price column, you would use the formula below:

MySelectedValue = SELECTEDVALUE(Profit[Price])

This will assign the value of the selected row in the Price column to the variable called MySelectedValue.

Store the Value in a Variable

The next thing to do is to store the value in a variable, which you can use later in your DAX formula. To do that, use the below syntax:

let MySelectedValue = SELECTEDVALUE(Profit[Price])

In this above example, Price is the value of the selected row in the column, and Profit is the table where Price is stored. The mySelectedValue is the variable of the assigned selected value which will be stored for future use.

Kindly note that:

  • If you select no value, the SELECTEDVALUE function will display an error.
  • Also, you can use the SELECTEDVALUE function in conjunction with other functions, such as SUMX, AVERAGEX, or COUNTX, for calculations on the selected value.
  • Finally, you can also use the SELECTEDVALUE function with a filter to return the selected value of a specific filtered set of rows.

E.g., SELECTEDVALUE(FILTER(Sales, Sales[Region] = "West"), Sales[Amount])

This above syntax will return the amount of the selected row only where the region is West.

Conclusion: How to Get the Value of the Selected Row in the Table to a Var in DAX

In conclusion, the SELECTEDVALUE function in DAX lets you get the value of the selected row in a table while taking two arguments: the table containing the selected row and the column from which you want to get the value.

Also, you can use this function with other DAX functions for calculations on the selected value or with a filter to return the selected value of a specific filtered set of rows.

Finally, it is important to note that the SELECTEDVALUE function will throw an error if there is no selected value.

Thanks for reading!