Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago

If statement not working with columns, only taking measures

Hi everyone!

 

So I've been trying to use if statements to calculate a conditional column. I've been trying to create a column called shift, based on the hour an employee worked. So if they worked between Hour 1-6, it is overnight shift, between 7-15, morning shift, and between 16-0, evening shift.

 

However Hour is a column. Everytime I go to try to use an IF statement or a Switch statement, it only accepts measures. How can I write something similar to an If Statement of a Switch statement that will return a column from columns? If somebody could give me the code, that would be great.

 

Thanks so much!

Kelly

1 Reply

  • tackytechtom's avatar
    tackytechtom
    Icon for Most Valuable Professional rankMost Valuable Professional

    Hi Anonymous,

     

    Do you mean something like this? 🙂

     

     

    Right click on a column in your table and choose New Column:

     

    Here the DAX:

    ShiftString = 
    SWITCH (
        TRUE,
        Table[Shift] = "1-6",  "Overnight Shift",
        Table[Shift] = "7-15", "Monring Shift",
        Table[Shift] = "16-0", "Evening Shift",
    BLANK()
    ) 

     

    Let me know if this helps 🙂

     

    /Tom
    https://www.tackytech.blog/
    https://www.instagram.com/tackytechtom/