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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
shadowsong42
Resolver I
Resolver I

Calculating a revised plantID with SWITCH

I have a fact table with (among other things) countryCode, countrySubDivisionCode, and plantID - all text columns. For everything other than US and Canada, I want to retain the original plantID. For US and Canada, I want to override the plantID with new values based on the countrySubDivisionCode.

When I try to create this as a calculated measure, it doesn't recognize the measure names, so I tried a calculated column instead. It didn't pop up any errors when I created the column with the below code, but when I tried to reference it in a visual, I got an error saying "a table of multiple values was supplied where a single value was expected".

Calculated Plant = 
VAR List4260 = { "NB", "NL", "NS", "ON", "PE", "QC" }
VAR List4790 = { "AB", "BC", "MB", "NT", "NU", "SK", "YT" }

RETURN
IF( OrderSlaLineItemDetail[countryCode] IN { "CA","US" },
    SWITCH(
        OrderSlaLineItemDetail[countrySubDivisionCode],
        List4260, "4260",
        List4790, "4790",
        OrderSlaLineItemDetail[plantId]
    ),
    OrderSlaLineItemDetail[plantId]
)

 

How do I need to change this to end up with a calculated plant assigned to each row of the fact table, in a way that will let me use it in a visual?

1 ACCEPTED SOLUTION
vicky_
Super User
Super User

Hi, 

the issue pops up because of the parts List4260, List4790 in the switch statement. Note - both of them are lists, when the SWITCH statement is trying to compare [countrySubDivisionCode] (which is a single string) against your list table of values. 

To fix this, you can try make the following change:

 

Calculated Plant = 
VAR List4260 = { "NB", "NL", "NS", "ON", "PE", "QC" }
VAR List4790 = { "AB", "BC", "MB", "NT", "NU", "SK", "YT" }

RETURN
IF( OrderSlaLineItemDetail[countryCode] IN { "CA","US" },
    SWITCH(TRUE(), 
        OrderSlaLineItemDetail[countrySubDivisionCode] IN List4260, "4260",
        OrderSlaLineItemDetail[countrySubDivisionCode] IN List4790, "4790",
        OrderSlaLineItemDetail[plantId]
    ),
    OrderSlaLineItemDetail[plantId]
) 

 

View solution in original post

2 REPLIES 2
v-pgoloju
Community Support
Community Support

Hi @shadowsong42 

Thank you for reaching out to the Microsoft Fabric Forum Community.


And also thanks to @vicky_  for prompt and useful response.

Just following up to see if the solution provided was helpful in resolving your issue. Please feel free to let us know if you need any further assistance.

If the response addressed your query, kindly mark it as Accepted Solution and click Yes if you found it helpful  this will benefit others in the community as well.

 

Best regards,

Prasanna Kumar

vicky_
Super User
Super User

Hi, 

the issue pops up because of the parts List4260, List4790 in the switch statement. Note - both of them are lists, when the SWITCH statement is trying to compare [countrySubDivisionCode] (which is a single string) against your list table of values. 

To fix this, you can try make the following change:

 

Calculated Plant = 
VAR List4260 = { "NB", "NL", "NS", "ON", "PE", "QC" }
VAR List4790 = { "AB", "BC", "MB", "NT", "NU", "SK", "YT" }

RETURN
IF( OrderSlaLineItemDetail[countryCode] IN { "CA","US" },
    SWITCH(TRUE(), 
        OrderSlaLineItemDetail[countrySubDivisionCode] IN List4260, "4260",
        OrderSlaLineItemDetail[countrySubDivisionCode] IN List4790, "4790",
        OrderSlaLineItemDetail[plantId]
    ),
    OrderSlaLineItemDetail[plantId]
) 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors