Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How do we fill the working hours between those two dates with Power Query?

Hello guys, Im trying to calculate the working hours between two dates using the formula Decimal.From but I can't get decimal number at the start/end of the shift. 

 

mobahi_0-1627312632650.png

 

mobahi_0-1627313181288.png

 

 

If the start and end shift have Whole number its well calculated but if the shift has a decimal number it shows an error.

Any suggestions will be highly appreciated.

Thank you guys 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

As @ edhans mentioned, if just create a list like {a..b}, the default increment is 1 and only use List.combine() to add decimal numbers.

In this case, if you want to create your expected column, you may create a conditional column using if statement and combine it with List.Combine() and List.Numbers(), like this:

    #"Added Custom2" = 
        Table.AddColumn(
            #"Added Custom1", "DATE ETAT", each 
                if [End_] - [Start_] < 1 then 
                    List.Combine({{[Start_]},{[End_]}}) 
                else if 
                    [Start_] = Number.RoundDown([Start_]) and [End_] = Number.RoundDown([End_]) then 
                    List.Numbers([Start_],[End_],1) 
                else if 
                    [Start_] = Number.RoundDown([Start_]) and [End_] > Number.RoundDown([End_]) then 
                    List.Combine({List.Numbers([Start_],Number.RoundDown([End_]) + 1,1),{[End_]}}) 
                else if 
                    [Start_] < Number.RoundUp([Start_]) and [End_] > Number.RoundDown([End_]) then 
                    List.Combine({{[Start_]},{Number.RoundUp([Start_])..Number.RoundDown([End_])} ,{[End_]}}) 
                else null
        )

11.png22.png

This is just an example, in your acutal table, you may need more conditions.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
edhans
Super User
Super User

You need to use the hour, from Time.Hour(). For example:

{Time.Hour(DateTime.Time([Start Date]))..Time.Hour(DateTime.Time([End Date]))}

This will generate a list that works. Lists must be integers.

edhans_0-1627324257640.png

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

Thank you @edhans  for your suggestion. Im trying to get the hour with its minutes in the list. I changed the hour to number so I can loop it and get the decimal number.

 

mobahi_0-1627395830628.png

 

I want the list to include Decimal numbers.

 

Thank you for your help

 

Hi @Anonymous ,

As @ edhans mentioned, if just create a list like {a..b}, the default increment is 1 and only use List.combine() to add decimal numbers.

In this case, if you want to create your expected column, you may create a conditional column using if statement and combine it with List.Combine() and List.Numbers(), like this:

    #"Added Custom2" = 
        Table.AddColumn(
            #"Added Custom1", "DATE ETAT", each 
                if [End_] - [Start_] < 1 then 
                    List.Combine({{[Start_]},{[End_]}}) 
                else if 
                    [Start_] = Number.RoundDown([Start_]) and [End_] = Number.RoundDown([End_]) then 
                    List.Numbers([Start_],[End_],1) 
                else if 
                    [Start_] = Number.RoundDown([Start_]) and [End_] > Number.RoundDown([End_]) then 
                    List.Combine({List.Numbers([Start_],Number.RoundDown([End_]) + 1,1),{[End_]}}) 
                else if 
                    [Start_] < Number.RoundUp([Start_]) and [End_] > Number.RoundDown([End_]) then 
                    List.Combine({{[Start_]},{Number.RoundUp([Start_])..Number.RoundDown([End_])} ,{[End_]}}) 
                else null
        )

11.png22.png

This is just an example, in your acutal table, you may need more conditions.

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

You cannot generate a list like that. At best what you could do is use logic to generate a list the integers from 1 to n-1, so 1..10, then append the last item with the decimal in it.

let
    Source = {1..10},
    Custom1 = List.Combine({Source, {11.7}})
in
    Custom1

It returns this list.

edhans_0-1627401682968.png

But there is no way to say "Generate a list from 1 to 11.7, increment by 1, until you get to 11.7, then tack on 11.7" without using some sort of combine operation as I have done here.

 



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors