Forum Discussion

andytmcc's avatar
andytmcc
Helper I
3 years ago
Solved

Add a Filter to a Switch

I have created a column that assigns a value (0, 0.5 or 1) based on the difference between 2 other columns:

 

locusofcontrol = SWITCH(

TRUE(),

'Loneliness All Data'[Locus Of Control Mean] > 'Loneliness All Data'[Locusofcontrol Previous Year],1,

'Loneliness All Data'[Locus Of Control Mean] = 'Loneliness All Data'[Locusofcontrol Previous Year],0.5,

0)
 
However, I only want these values to be created when the value "PC" is in the "Variable" column. How do I add the filter part into this DAX code?
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi,

     

    Try like this

     

    test_switch = switch(
    True(),
    and('Table'[Product]=1,'Table'[Serial Number]=99),1,
    and('Table'[Product]=1,'Table'[Serial Number]<>99),2,0)

2 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    andytmcc Maybe:

    locusofcontrol = SWITCH(
    
    TRUE(),
    
    MAX('Loneliness All Data'[PC]) = "Variable" && 'Loneliness All Data'[Locus Of Control Mean] > 'Loneliness All Data'[Locusofcontrol Previous Year],1,
    
    MAX('Loneliness All Data'[PC]) = "Variable" && 'Loneliness All Data'[Locus Of Control Mean] = 'Loneliness All Data'[Locusofcontrol Previous Year],0.5,
    
    0)
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi,

     

    Try like this

     

    test_switch = switch(
    True(),
    and('Table'[Product]=1,'Table'[Serial Number]=99),1,
    and('Table'[Product]=1,'Table'[Serial Number]<>99),2,0)