A
C
- CALCULATE
- CALCULATETABLE
- CALENDAR
- CALENDARAUTO
- CEILING
- CHISQ.DIST
- CHISQ.DIST.RT
- CHISQ.INV
- CHISQ.INV.RT
- CLOSINGBALANCEMONTH
- CLOSINGBALANCEQUARTER
- CLOSINGBALANCEYEAR
- COALESCE
- COLUMNSTATISTICS
- COMBIN
- COMBINA
- COMBINEVALUES
- CONCATENATE
- CONCATENATEX
- CONFIDENCE.NORM
- CONFIDENCE.T
- CONTAINS
- CONTAINSROW
- CONTAINSSTRING
- CONTAINSSTRINGEXACT
- CONVERT
- COS
- COSH
- COT
- COTH
- COUNT
- COUNTA
- COUNTAX
- COUNTBLANK
- COUNTROWS
- COUNTX
- COUPDAYBS
- COUPDAYS
- COUPDAYSNC
- COUPNCD
- COUPNUM
- COUPPCD
- CROSSFILTER
- CROSSJOIN
- CUMIPMT
- CUMPRINC
- CURRENCY
- CURRENTGROUP
- CUSTOMDATA
D
E
I
N
O
P
R
S
- SAMEPERIODLASTYEAR
- SAMPLE
- SEARCH
- SECOND
- SELECTCOLUMNS
- SELECTEDMEASURE
- SELECTEDMEASUREFORMATSTRING
- SELECTEDMEASURENAME
- SELECTEDVALUE
- SIGN
- SIN
- SINH
- SLN
- SQRT
- SQRTPI
- STARTOFMONTH
- STARTOFQUARTER
- STARTOFYEAR
- STDEVX.P
- STDEVX.S
- STDEV.P
- STDEV.S
- SUBSTITUTE
- SUBSTITUTEWITHINDEX
- SUM
- SUMMARIZE
- SUMMARIZECOLUMNS
- SUMX
- SWITCH
- SYD
T
U
The SELECTEDMEASURENAME function is a key component of the DAX language, allowing users to dynamically reference the name of the currently selected measure in a table or visualization. This can be extremely useful when creating complex calculations and visualizations that require the use of different measures.
In this article, we will explore how to use the SELECTEDMEASURENAME function in Power BI, including examples and best practices.
Understanding the SELECTEDMEASURENAME Function
The SELECTEDMEASURENAME function is a DAX function that returns the name of the currently selected measure in a table or visualization. This can be useful when creating complex calculations that require the use of different measures, as it allows users to dynamically reference the name of the measure.
For example, let’s say you have a table with multiple measures, such as sales, profit, and revenue. You want to create a calculation that calculates the percentage change in sales from the previous year. Using the SELECTEDMEASURENAME function, you can dynamically reference the name of the sales measure and create a calculation that works for any measure without having to manually update the formula.
Using the SELECTEDMEASURENAME Function
To use the SELECTEDMEASURENAME function in Power BI, you first need to create a measure that references it. Here’s an example:
Measure Name = SELECTEDMEASURENAME()
This measure will return the name of the currently selected measure in the table or visualization.
Once you have created the measure, you can use it in other calculations and visualizations. For example, let's say you want to create a visualization that shows the percentage change in sales from the previous year:
1. Create a new visualization, such as a line chart or bar chart.
2. Add the sales measure to the Values field.
3. Add the date field to the Axis field.
4. Add the Measure Name measure to the Legend field.
5. Create a new measure that calculates the percentage change in sales from the previous year:
Percentage Change =
VAR CurrentMeasure = SELECTEDMEASURENAME()
VAR PrevYearSales = CALCULATE(CurrentMeasure, DATEADD(‘Date'[Date], -1, YEAR))
VAR CurrentSales = CurrentMeasure
RETURN DIVIDE(CurrentSales – PrevYearSales, PrevYearSales) * 100
This measure uses the SELECTEDMEASURENAME function to dynamically reference the name of the sales measure, and calculates the percentage change in sales from the previous year.
6. Add the Percentage Change measure to the Values field of the visualization.
By using the SELECTEDMEASURENAME function, you can create visualizations and calculations that work with any measure, without having to manually update the formula.
Best Practices
Here are some best practices when using the SELECTEDMEASURENAME function in Power BI:
- Use the function sparingly: While the SELECTEDMEASURENAME function can be useful in certain scenarios, it can also make your formulas and calculations more complex. Try to use it only when necessary.
- Use descriptive measure names: When creating measures, use descriptive names that make it clear what the measure does. This will make it easier to use the SELECTEDMEASURENAME function and other DAX functions.
- Test your calculations: Before using a formula with the SELECTEDMEASURENAME function in a production environment, be sure to test it thoroughly to ensure it is working as expected.
The SELECTEDMEASURENAME function is a powerful tool in the Power BI DAX language, allowing users to dynamically reference the name of the currently selected measure in a table or visualization. By using this function, you can create visualizations and calculations that work with any measure, without having to manually update the formula. By following best practices and testing your calculations, you can use the SELECTEDMEASURENAME function to create more efficient and effective Power BI reports and dashboards.