Forum Discussion

jamieham's avatar
jamieham
Helper II
6 years ago

SWITCH

I'm trying to create a new column using the SWITCH function and I'm using the DAX formula below. The issue I have is if there is a blank for Gainline Prev the DAX formula is reading it as a 0 and adding Negative GL. How do I get it to ignore cells that are blank or is there a better way of doing it?

 

Gainline Prev                   Gainline
0                                      Negative GL
0                                      Negative GL
1                                      Positive GL
                                        Negative GL (dont want this to show)
0                                      Negative GL
1                                      PositiveGL
 
Gainline = SWITCH(TRUE(),default[Gainline Prev]=1,"Positive GL",default[Gainline Prev]=0,"Negative GL")
 
 

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    HI jamieham 

     

    In the filter pane for the Gainline Prev, you can say to ignore blank as below

     

  • jamieham ,

    You can create a measure like

    calculate([Meausre], filter(Table, not(isblank(Table[Gainline Prev]))))

     

    Or you can use visual level or page filter Table[Gainline Prev] <> Blank ()

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi jamieham  ,

    According to my understanding, you want to use switch() to create a new column and filter the blank row, right?

     

    You could use the following formula:

    Gainline =
    VAR _blank =
        ISBLANK ( SELECTEDVALUE ( Default[Gainline Prev] ) )
    RETURN
        SWITCH (
            TRUE (),
            SELECTEDVALUE ( Default[Gainline Prev] ) = 1
                && _blank = FALSE (), "Positive GL",
            SELECTEDVALUE ( Default[Gainline Prev] ) = 0
                && _blank = FALSE (), "Negative GL"
    )

    My visualization looks like this:

    Is the result what you want? If you have any questions, please upload some data samples and expected output.

    Please do mask sensitive data before uploading.

     

    Best Regards,

    Eyelyn Qin

    • jamieham's avatar
      jamieham
      Helper II
      I've attached a small sample of the data. I want to create a new column called Gainline that looks at Previous GL and adds Positive GL if the number is 1 and Negative GL if the number is 0. The issue I've had is that it's adding Negative GL if the cell is blank in Previous GL.
       
      I want to add a column as per the attached table that is highlighted in red.
       
      Hope that all makes sense.
       
      Regards
       
      Jamie
       
      TeamTeam IDPlay NumSet NumPS TimestampPS EndstampHome TeamAway TeamMatch TimeHalfScore_AdvantageDescriptionMetresX_CoordX_Coord EndY_CoordY_Coord EndAction TypeAction ResultGainline NextGainline PrevGainline
      Team 1500310372467250Team 1Team 2795627Ruck082080NAWon Outright10Negative GL
      Team 1500410372577261Team 1Team 2800827Ruck0870440NAWon Outright11Positive GL
      Team 1500510372657269Team 1Team 2801627Ruck0890580NAWon Outright11Positive GL
      Team 3885011412Team 3Team 41010Possession1380936668Start Set 50m Restart RetainedEnd Set Own Lineout  
      Team 388506244101Team 3Team 413110Possession392956853LineoutEnd Pen Won  
      Team 4300024164178Team 3Team 425710Possession-154011Start Set Lineout StealEnd Scrum