cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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_Concept Related Kiosk_Concept Product Type Product Category ABC ABC XYZ Bks Made ABC Wok

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
Super User

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

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Helper I

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.

Super User

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

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Helper I

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?

Super User

@BachDinh I don't see why not.

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Helper I

@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