Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

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 1
tackytechtom
Super User
Super User

Hi @Anonymous,

 

Do you mean something like this? 🙂

tomfox_1-1654538998742.png

 

 

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

tomfox_0-1654538814635.png

 

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/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.