What is SELECTEDMEASURE?
SELECTEDMEASURE is a DAX function that returns the name of the currently selected measure in a Power BI report. When you create a report in Power BI, you can add multiple measures to it. Measures are calculations that are based on the data in your dataset. For example, you can create a measure to calculate the total sales for a particular product category.
When you add a measure to a visual in your report, Power BI automatically selects that measure. You can use the SELECTEDMEASURE function to reference the currently selected measure in other calculations and visuals in your report.
How to Use SELECTEDMEASURE
To use the SELECTEDMEASURE function in Power BI, you need to follow these steps:
1. Open Power BI Desktop and create a new report.
2. Add a visual to your report and select a measure from the Fields pane.
3. Click on the ellipsis (…) next to the measure and select “New measure” from the drop-down menu.
4. In the formula bar, enter the following formula: = SELECTEDMEASURE()
5. Give the new measure a name and click “Enter” to save it.
Once you have created a measure using the SELECTEDMEASURE function, you can use it in other calculations and visuals in your report. For example, you can create a new visual that shows the percentage of total sales for each product category using the following formula:
Percentage of Total Sales = DIVIDE([Total Sales], CALCULATE([Total Sales], ALL(‘Product'[Category])))
In this formula, [Total Sales] is the name of the measure that you created using the SELECTEDMEASURE function. The CALCULATE function is used to calculate the total sales for all product categories, while the ALL function is used to remove any filters on the Category column.
Benefits of Using SELECTEDMEASURE
The SELECTEDMEASURE function has several benefits for Power BI users. Here are some of the key benefits:
1. Flexibility: The SELECTEDMEASURE function allows you to create dynamic calculations that change based on the measure selected by the user. This makes your reports more flexible and interactive.
2. Efficiency: Using the SELECTEDMEASURE function can help you save time and effort by reducing the need to create multiple versions of the same calculation for different measures.
3. Consistency: By referencing the currently selected measure in your calculations, you can ensure that your visuals and reports are consistent and accurate.
The SELECTEDMEASURE function is a powerful tool for Power BI users. It allows you to create dynamic calculations that change based on the measure selected by the user. By using this function, you can create more flexible, efficient, and consistent reports in Power BI. So, if you haven't already, give the SELECTEDMEASURE function a try and see how it can improve your reports.