Forum Discussion
ElliotP
9 years agoPost Prodigy
How to Create DayName + TimePeriod
Evening, I have my data table, my date table and my time table. I'm trying to be able to calculate "Monday Morning". At the moment, I'm able to calculate the Day name from my Date Key using forma...
- 9 years ago
It sounds like you are going with Phil_Seamark's formula so just use a SWITCH to do all your nested IFs like this...
Day and Time = FORMAT ( 'itemdetailsdogfood$'[Date], "dddd " ) & SWITCH ( TRUE (), 'itemdetailsdogfood$'[Time] >= TIMEVALUE ( "00:00:00" ) && 'itemdetailsdogfood$'[Time] <= TIMEVALUE ( "06:00:00" ), "Night", 'itemdetailsdogfood$'[Time] > TIMEVALUE ( "06:00:00" ) && 'itemdetailsdogfood$'[Time] <= TIMEVALUE ( "09:00:00" ), "Early Morning", 'itemdetailsdogfood$'[Time] > TIMEVALUE ( "09:00:00" ) && 'itemdetailsdogfood$'[Time] <= TIMEVALUE ( "12:00:00" ), "Morning", 'itemdetailsdogfood$'[Time] > TIMEVALUE ( "12:00:00" ) && 'itemdetailsdogfood$'[Time] <= TIMEVALUE ( "18:00:00" ), "Afternoon", 'itemdetailsdogfood$'[Time] > TIMEVALUE ( "18:00:00" ) && 'itemdetailsdogfood$'[Time] <= TIMEVALUE ( "21:00:00" ), "Evening", "Late Evening" )Good Luck! :smileyhappy:
Sean
9 years agoCommunity Champion
It sounds like you are going with Phil_Seamark's formula so just use a SWITCH to do all your nested IFs like this...
Day and Time =
FORMAT ( 'itemdetailsdogfood$'[Date], "dddd " )
& SWITCH (
TRUE (),
'itemdetailsdogfood$'[Time] >= TIMEVALUE ( "00:00:00" )
&& 'itemdetailsdogfood$'[Time] <= TIMEVALUE ( "06:00:00" ), "Night",
'itemdetailsdogfood$'[Time] > TIMEVALUE ( "06:00:00" )
&& 'itemdetailsdogfood$'[Time] <= TIMEVALUE ( "09:00:00" ), "Early Morning",
'itemdetailsdogfood$'[Time] > TIMEVALUE ( "09:00:00" )
&& 'itemdetailsdogfood$'[Time] <= TIMEVALUE ( "12:00:00" ), "Morning",
'itemdetailsdogfood$'[Time] > TIMEVALUE ( "12:00:00" )
&& 'itemdetailsdogfood$'[Time] <= TIMEVALUE ( "18:00:00" ), "Afternoon",
'itemdetailsdogfood$'[Time] > TIMEVALUE ( "18:00:00" )
&& 'itemdetailsdogfood$'[Time] <= TIMEVALUE ( "21:00:00" ), "Evening",
"Late Evening"
)Good Luck! :smileyhappy:
Phil_Seamark
9 years agoMicrosoft Employee
I like the way the SWITCH statement has been used here to allow ranges. No excuses for nested IF statement ever again!