Forum Discussion
"IF" DAX function SSAS live
- 6 years ago
Hi,
Try this measure
=IF(HASONEVALUE(DIM_ORG[UNIT_NM]),IF(VALUES(DIM_ORG[UNIT_NM])="Contoso","Contoso Inc",VALUES(DIM_ORG[UNIT_NM])),BLANK())
Unlike what you would expect in Excel, or a SQL table, a measure has no direct access to a column in a specific row. However, if you're writing a measure to execute in a table or matrix visual, there will not be a "row context" the way there would be if you were writing a calculated colum.
There are functions you can use to retreive a value from a filter context when you are using the measure as a column in a table or a matrix. You might write your measure like this: Measure = IF(SELECTEDVALUE(DIM_ORG[UNIT_NM],"")="Contoso","Contoso Inc",SELECTEDVALUE(DIM_ORG[UNIT_NM],"")). The function SELECTEDVALUE returns the value of the column reference passed as first argument if it is the only value available in the filter context, otherwise it returns blank or the default value passed as second argument. https://www.sqlbi.com/articles/using-the-selectedvalue-function-in-dax/
You might consider using a variable: VAR unit_nm = SELECTEDVALUE(DIM_ORG[Unit_NM],"")
RETURN IF(unit_nm = "Contoso","Contoso Inc", unit_num)
Using variables lets you debug, as you can "RETURN" the variable unit_num to check that it is getting the value you think it is. That often turns out to be very helpful.
I learn something every time I answer a question
I'm a personal Power BI trainer