cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
ijheyburn Frequent Visitor
Frequent Visitor

DAX Help With Nested If

Hello 

I hope a kind soul may be able to help me out.  I am trying to convert the attached Cognos case statement into a DAX statement, in a caclulated column.  I have been trying for a whole using a mix of if(and and if(isblank and so on but simply cannot get my head around it and hence can't get it written to produce the correct result.  

Any DAX heroes suggest a statement that might work pretty please?

 

Result_Case.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
DouweMeer Member
Member

Re: DAX Help With Nested If

Something like this?

Switch ( true ( )

, [field1] = blank() && [field2] = blank() , "double oops"

, [field1] = blank() , "type-1 oops"

, [field2] = blank(), "type-2 oops"

, "Undefined"

)

View solution in original post

6 REPLIES 6
ORBI Regular Visitor
Regular Visitor

Re: DAX Help With Nested If

Use Switch statement in DAX. It will solve your problem.
Nathaniel_C Super Contributor
Super Contributor

Re: DAX Help With Nested If

Hi @ijheyburn ,

Try using a SWITCH() Switch is a link to explanation, and there are a lot of videos out there as well.

SWITCH([Month],
               1,"January",
               2,"February",
                "Some other month"
               )

Takes a group of nested ifs and turns it into a readable function. The function stops at the first one that is true.  I always think of it as a penny dropped into a pond, and if there is nothing to stop it (nothing true) then you get the value at the bottom.
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel

d_a_n_c_ Regular Visitor
Regular Visitor

Re: DAX Help With Nested If

Or if you want to stay with if please see below. I didn't do exactly the same to yours but used all logical tests you need. Just replace it with your values.

Play with it as it works, just tested it.

 

fix = if(max(stores[Store name]) = "Aberfeldy", "Aberfeldy store",
if(max(stores[Store name]) = "Abergele", "store",
if(and(max(stores[Store name]) = "Abertillery",max(stores[Store number]) = 173),"warehouse",0)))
 
daniel
ijheyburn Frequent Visitor
Frequent Visitor

Re: DAX Help With Nested If


@Nathaniel_C wrote:

Hi @ijheyburn ,

Try using a SWITCH() Switch is a link to explanation, and there are a lot of videos out there as well.

SWITCH([Month],
               1,"January",
               2,"February",
                "Some other month"
               )

Takes a group of nested ifs and turns it into a readable function. The function stops at the first one that is true.  I always think of it as a penny dropped into a pond, and if there is nothing to stop it (nothing true) then you get the value at the bottom.
Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel


Hey Nathaniel


Thanks for your reply - I've been having a play with 'Switch' since you kindly replied but am still struggling.  I think it is the mixture of the AND conditions mixed with me trying to compare where there are potentially blank values that are throwing me.  Also as I am calling different fields in the expression - do I need to nest the switch?  I'm very confused 😞

DouweMeer Member
Member

Re: DAX Help With Nested If

Something like this?

Switch ( true ( )

, [field1] = blank() && [field2] = blank() , "double oops"

, [field1] = blank() , "type-1 oops"

, [field2] = blank(), "type-2 oops"

, "Undefined"

)

View solution in original post

ijheyburn Frequent Visitor
Frequent Visitor

Re: DAX Help With Nested If

That seems to have done the trick thank you very much. That pesky double ampersand always catches me out - I was trying to incorporate AND statements but your suggestion seems to have worked. Thank you

Helpful resources

Announcements
October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Badges

Incoming: New and Improved Badges

Exciting news: We've given our badges an overhaul and added brand news ones.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 143 members 1,793 guests
Please welcome our newest community members: