Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
BachDinh
Helper I
Helper I

IF chain spot check -> Chain not working properly

Hi,

 

I have a following chain of IFs for a calculated column, that doesn't seem to work properly and I cannot figure out why, as logically each steps should be fine. 

 

 

 

Product Category= 
IF(
    --ABC Bks
   AND([Related Kiosk_Concept] IN {"ABC", "Multibrand"}, CONTAINSSTRING(Products[Product],"Bks"))
   , "ABC Bks"
     --ABC Non-Bks
   , IF(
       [Related Kiosk_Concept] IN {"ABC", "Multibrand"} && Products[Type] IN {"Made abc","Made ABC"} && NOT(CONTAINSSTRING(Products[Product],"Bks"))
       ,"ABC Non-Bks"
    --Wok
       ,IF(
            [Related Kiosk_Concept] = "MainABCLight" && Products[Type] = "Made ABC"
            ,"Wok"
    --Main Product 
            ,IF([Related Kiosk_Concept] = "Main" && Products[Type] = "Made" && Products[Leaf Cat] IN 
            {"1","B2","3","4", "5","6","7","8", "9"}
            ,"Main Product"
            ,""
            )
       )
   )
)

 

 

 

The output of this seems to be either 'Wok' or Blank. 

One of the outputs is as follows: 

Kiosk_ConceptRelated Kiosk_ConceptProductTypeProduct Category
ABCABCXYZ BksMade ABCWok

 

It looks like it should have been caught in the first couple IF -> The [Related Kiosk_Concept] is ABC, and the Product contains "Bks", so the output should be 'ABC bks', but it skips that and somehow gets 'Wok'. 

 

This might be a simple silly mistake, but I cannot figure it out, so I would appreciate help. 

6 REPLIES 6
Greg_Deckler
Super User
Super User

@BachDinh These kinds of things are easier to debug if you switch to using SWITCH(TRUE(),...) instead of nested IF statements.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

 

I have switched it to 

 

Product Category = 
SWITCH(
    TRUE()
    ,AND([Related Kiosk_Concept] IN {"ABC", "Multibrand"}, CONTAINSSTRING(Products[Product],"Bks")), 
        "ABC Bks"
    ,[Related Kiosk_Concept] IN {"ABC", "Multibrand"} && Products[Type] IN {"Made abc","Made ABC"} && NOT(CONTAINSSTRING(Products[Product],"Bks")),
        "ABC Non-Bks"
    ,[Related Kiosk_Concept] = "MainABCLight" && Products[Type] = "Made ABC",
        "Wok"
    ,[Related Kiosk_Concept] = "Main" && Products[Type] = "Made" && Products[Leaf Cat] IN {"list"}
    ,""
)

 

The issue is still present, with the example output in my original post being the same. 

 

EDIT: From looking at the results, it almost seems like it is only looking whether the Type is 'Made ABC' and assigning 'Wok' or blank based on the result of that check.

@BachDinh Wait, I recognize this, did you convert your relationship between Kiosks table and that other table to Both direction instead of single?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

Curiously enough, I've tried the below both as a calculated column and as a measure: 

SWITCH(
    TRUE()
    ,[Related Kiosk_Concept] = "ABC", "ABC"
    ,[Related Kiosk_Concept] = "Multibrand","Multibrand"
    ,[Related Kiosk_Concept] = "MainABCLight" ,"Wok"
    ,[Related Kiosk_Concept] = "Main","Main"
    ,""
)

For the calculated column, it only outputs WOK. No blanks. 

For the measure, it works fine. 

Is there a way perhaps to do the entire nexted IFs / SWITCH(TRUE() ) in a measure instead of the calculated column?

@BachDinh I don't see why not.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler I didn't, since my workaround works and provides a valid output linking product to [kiosk_concept]. 

I did change it to see whether it would help, but it broke multiple visuals with an invalid handle error, so I changed it back. Considering that the measure inside the calculated column returns the correct 'Kiosk_concept), I am not sure whether changing relationship direction woudd matter much

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors