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
jess_v
Frequent Visitor

"IF" DAX function SSAS live

Hello,

 

DAX total newbie here.  I'm trying to do a simple measure.  If the unit name (the column "DIM_ORG[UNIT_NM]") is "Contoso" then show "Contoso Inc", otherwise show the orignal value of the unit name.  However, when I try t add that column to my IF statement, it does not find it.  All I see listed are measures.  

 

DAX IF.png

 

My expected function would be: 

 

Measure = IF(DIM_ORG[UNIT_NM]="Contoso","Contoso Inc",DIM_ORG[UNIT_NM])

 

I would like to point out I am using an SSAS Live connection, so I can't create columns.  I understand that some DAX functions are not available with SSAS, but I belive IF is supported. 

 

Any help would be appreciated.  Thanks!

 
1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

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())


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

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())


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
kentyler
Solution Sage
Solution Sage

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 





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors