Moderators
January 31, 2022
I suspect that this is due to the fact that you are dealing with texts, not real time values. Could it be that the time 08:40:00 contains a leading space? The text " 08;40:00" will be evaluated as greater than the text "23:00", thus returning "Night"
In Power Query, make sure that you set the data type for the call time column to Date/Time. Then extract the time only into the time_for_shift_sebregation column.
And the code for the added column should use the #time() function. It could look like this:
if [time_for_shift_segregation] >= #time(23,0,0) then "Night" else
if [time_for_shift_segregation] >= #time(15,0,0) then "Evening" else "Morning"
If this makes no sense, please upload a file containing the underlying data and query for what is show shown in your screenshot.
Moderators
January 31, 2022
Moderators
January 31, 2022
Thanks for the file. Any particular reason why it's in the old xls format?
I couldn't really follow through your query as it connected to files in a folder on your computer. But I took your script and connected it to the table in Sheet1, assuming that this is the data you worked off. You'll find it in the "Table1" query that loads the green table in Sheet3.
At the point where you added the column that "calculates" the Shift, the [time_for_shift_segmentation] column is NOT set to Date. It's still a Text. Corrected that and changed the next step to the formula I mentioned earlier (though I misread segmentation for segregation in my response).
Then the query and/or data generated errors in the last column. I just replaced them wit 00:00:00.
Since the data table did not have the problem records that you showed in your screenshots in it, I added a TEST row with an 08:40:00 time stamp which correctly becomes "Morning".
See attached file (saved as an xlsx, by the way).
1 Guest(s)