Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers!
Enter the sweepstakes now!Preparing for a certification exam? Ask exam experts all your questions on May 15th. Register now.
Alright all you fabulous PowerBI gurus - I need help creating a table that tells me each hour between two date/time columns.
I was able to do this without issue when creating a table that was looking at just dates, but I would like the same thing but hours. What worked for dates:
In the original dataset it's one line item: Cell, Project type, PPN, starttime, endtime, Site. As you can see the hours are all 12AM.
How on earth do I get the other data in there as well? Or is there an easier way to figure out how many hours are running on each shift?
Any advice/guidance/help is greatly appreciated!
Solved! Go to Solution.
If all you need to know is how many hours are spent on each shift I would try something like...
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTLSN7TUNzIwMlEwNLAyMACLGBlARYxBIrE60UpJqCrNYSphIkaGMJXJKCYYAFUaoogYGVuZWirFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, start = _t, end = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"id", type text}, {"start", type datetime}, {"end", type datetime}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "HoursInBetween", each List.Transform(List.DateTimes([start], Duration.TotalHours([end]-[start]), #duration(0,1,0,0)), each DateTime.ToText(_, [Format="HH"]))),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "firstShiftHours", each List.Count(List.Intersect({[HoursInBetween], firstShift}))),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "secondShiftHours", each List.Count(List.Intersect({[HoursInBetween], secondShift}))),
#"Added Custom3" = Table.AddColumn(#"Added Custom2", "thirdShiftHours", each List.Count(List.Intersect({[HoursInBetween], thirdShift})))
in
#"Added Custom3"
with the firstShift List defined as
let
Source = {"07", "08", "09", "10", "11", "12", "13", "14"}
in
Source
second shift list
let
Source = {"15", "16", "17", "18", "19", "20", "21", "22"}
in
Source
third shift list
let
Source = {"23", "00", "01", "02", "03", "04", "05", "06"}
in
Source
In this example I started with...
and ended with...
Proud to be a Super User! | |
So when I enter this and update with my dataset, I can see the data generate in the Power Query window, but I get an error when it tries to load the data - I get a "OLE DB or ODBC error: [Expression.Error] We cannot conver the null value to number. I cannot figure out where that error is originating from. There are no null values in the table (I put a step in to replace them). now we are talking over 7M rows of data...not sure if that is the problem or not. but as you can see in the screenshot I do get the same dataset you're showing but with my data (again, only in the power query screen)
Any clue what could be causing the error or where to start looking?
My first suggestion would be to add a 'Keep Errors' step to find out which rows are causing the issue. From that point you may get more insight as to which column is causing the error. A null date value in either the start or end column will cause that error to occur.
Proud to be a Super User! | |
If all you need to know is how many hours are spent on each shift I would try something like...
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUTLSN7TUNzIwMlEwNLAyMACLGBlARYxBIrE60UpJqCrNYSphIkaGMJXJKCYYAFUaoogYGVuZWirFxgIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [id = _t, start = _t, end = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"id", type text}, {"start", type datetime}, {"end", type datetime}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "HoursInBetween", each List.Transform(List.DateTimes([start], Duration.TotalHours([end]-[start]), #duration(0,1,0,0)), each DateTime.ToText(_, [Format="HH"]))),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "firstShiftHours", each List.Count(List.Intersect({[HoursInBetween], firstShift}))),
#"Added Custom2" = Table.AddColumn(#"Added Custom1", "secondShiftHours", each List.Count(List.Intersect({[HoursInBetween], secondShift}))),
#"Added Custom3" = Table.AddColumn(#"Added Custom2", "thirdShiftHours", each List.Count(List.Intersect({[HoursInBetween], thirdShift})))
in
#"Added Custom3"
with the firstShift List defined as
let
Source = {"07", "08", "09", "10", "11", "12", "13", "14"}
in
Source
second shift list
let
Source = {"15", "16", "17", "18", "19", "20", "21", "22"}
in
Source
third shift list
let
Source = {"23", "00", "01", "02", "03", "04", "05", "06"}
in
Source
In this example I started with...
and ended with...
Proud to be a Super User! | |
Check out the April 2025 Power BI update to learn about new features.
Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.
User | Count |
---|---|
78 | |
76 | |
70 | |
49 | |
42 |
User | Count |
---|---|
56 | |
47 | |
33 | |
32 | |
28 |