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
kan
Helper I
Helper I

SWITCH or IF in calculated columns

Hi,

 I want to create a calculated column named Category from  two tables

DWSP 

DInOutdoor

 

DWSP table has column named WSP 

DInOutdoor has column named InOutdoor

 

Following is the condition I need to implement.

 

If WSP = ‘STG’ then ‘Strategic’

Else if InOutdoor = ‘Indoor’ then ‘Indoor’

Else if InOutdoor = ‘Oudoor’ then ‘Oudoor’

Else ‘Unknown’

 

I know how to use switch with single table.Can someone help me how to write above condition when using tables.

 

Thanks..

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @kan

 

You need to use SWITCH().

 

New col = 
VAR  vInOut = RELATED(DInOutdoor[InOutdoor])
RETURN
SWITCH ( TRUE(),
          Dwsp[Wsp]= "STG".Strategic,
         vInOut = "Indoor","Indoor",
         vInout= "Outdoor","Outdoor",
         "Unknown")

 

Thanks

Raj

View solution in original post

Thanks @AnonymousRaj for the solution.

View solution in original post

5 REPLIES 5
v-yulgu-msft
Employee
Employee

Hi @kan,

 

In which table you need to create such a calculated column? Is there any relationship between these two tables? Please provide dummy data to illustrate your scenario.

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @kan

 

You need to use SWITCH().

 

New col = 
VAR  vInOut = RELATED(DInOutdoor[InOutdoor])
RETURN
SWITCH ( TRUE(),
          Dwsp[Wsp]= "STG".Strategic,
         vInOut = "Indoor","Indoor",
         vInout= "Outdoor","Outdoor",
         "Unknown")

 

Thanks

Raj

What if the DInOutdoor table is on the Many side? How to use RelatedTable then?

Thanks Raj for the solution.

Thanks @AnonymousRaj for the solution.

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.