Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

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..

  • Anonymous's avatar
    Anonymous
    8 years ago

    Hi Anonymous

     

    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

  • Anonymous's avatar
    Anonymous
    8 years ago

    Thanks AnonymousRaj for the solution.

5 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous

     

    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

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks Raj for the solution.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Thanks AnonymousRaj for the solution.

    • ziyabikram96's avatar
      ziyabikram96
      Helper V

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

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi Anonymous,

     

    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