Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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.
@BachDinh These kinds of things are easier to debug if you switch to using SWITCH(TRUE(),...) instead of nested IF statements.
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?
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.
@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
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
113 | |
109 | |
100 | |
39 | |
31 |
User | Count |
---|---|
154 | |
122 | |
77 | |
74 | |
44 |