Forum Discussion
Creating conditional column based on time for another column
Dear All
I created 3 global variables with name: Morning, Noon and evening and I set default values '11:00' ,'16:00' and '23:59' for each variable respectively. Now I need to add new condition column based on column name called time_open_at check if the time <= Morning then it's breakfast, and BTW Morning And Noon then 'Lunch' otherwise if > Noon and < Evening then 'Dinner' how shall I do this?
21 Replies
- Greg_DecklerCommunity Champion
Are you doing this in Power Query (M) code or in the data model and want to use DAX?
- MAAbdullah47Helper V
I'm Using It In Power BI DiskTop, I'm still new Kindly give me the way of doing it regardless using M or any other methods.
- Greg_DecklerCommunity Champion
Are you doing this in Power Query (M) code or in the data model and want to use DAX?
- MAAbdullah47Helper V
The User group moved and I couldn't found the answer.
- Greg_DecklerCommunity Champion
Here is one way and you do not need any kind of global variable or anything, just a calculated column like this:
Column = IF([Time]<TIME(11,0,0),"Morning",IF([Time]<TIME(16,0,0),"Noon","Evening"))
You could modify this to just do less than 16:00:00 be Lunch, otherwise "Dinner".