Forum Discussion
Recognise Column as a Time?
camargos88 Appreciate the reply. Unfortunately, that didn't work for me. I found another way around it though. I went into my data set and unpivoted the set so that there's a half hour 1, half hour 2 etc. value for each date. Now my problem is changing all the times in the date column to match the half hour 1, 2 etc.
Sample data (what it looks like now):
| Date | Attribute | Value |
| 01/01/2020 00:00:00 | Half hour 1 | 10 |
| 01/01/2020 00:00:00 | Half hour 2 | 12 |
| 01/01/2020 00:00:00 | Half hour 3 | 15 |
| 01/01/2020 00:00:00 | Half hour 4 | 16 |
CalvinL ,
The m code does it.
Check this file: Download PBIX
Did I answer your question? Mark my post as a solution!
Ricardo
- camargos886 years ago
Community Champion
- CalvinL6 years ago
Helper II
Hi camargos88
Thanks for that. That file seemed to work for me too.. appreciate you answering all of my questions! I've marked your original file post as the solution.
- CalvinL6 years ago
Helper II
Thank you for the file. So that custom column works, but only goes as far as 04:30:00 for some reason and then just repeats from there. Any ideas as to why it does that?
Also, would there be a solution to just increment the time in the date column rather than creating a new separate column for this?
- camargos886 years ago
Community Champion
Hi CalvinL ,
The formula to transform get the last character and transform it to hour like
Hour 4 = The formula gets the last character and multiply it by 30.
Duration.ToText(#duration(0,0, Number.FromText(Text.End([Attribute], 1)) * 30, 0))
The last value is Hour 9, so it is 04:30 starting from 00:00.
If you need the Hour 1 to be 00:00 the code is like
Duration.ToText(#duration(0,0, (Number.FromText(Text.End([Attribute], 1)) 1) * 30, 0))
So Hour 9 would be like 4:00.
I didn't get this part:
"Also, would there be a solution to just increment the time in the date column rather than creating a new separate column for this?"
Can you give me some example ?
- CalvinL6 years ago
Helper II
Thank you camargos88
So I've got 48 values for half hour.. how would my code look like for that? Half hour 1 would be 00:30, half hour 2 would be 01:00 up to half hour 48 which would be 00:00
Re: "Also, would there be a solution to just increment the time in the date column rather than creating a new separate column for this?"
What i meant by that is - can we use a function like the DateAdd function to just increment the current date column by +00:30?
- camargos886 years ago
Community Champion
Hi CalvinL ,
I didn't try it after Hour 9, so the code would be like:
Duration.ToText(#duration(0, 0, 30, 0) * Number.FromText(Text.Split([Attribute], " "){2}))
Also, Hour 48 will be next day ?
I've updated the file.
- CalvinL6 years ago
Helper II
camargos88 Values are being recorded every half hour (30 mins) hence the 00:30. Sorry for any confusion.