Search code examples
powerquerym

Convert decimal duration in hours (xxx.xxx) to time format duration in hours (hh:mm:ss)


All search results have so far pointed to DAX measures, even for those posts located in Power Query-specific forums. I would really like an M code solution.

Fuel Injection [°] Speed [rpm] Duration [h]
15 400 2.81
15 450 2.49
15 500 3.02
15 520 1.18
15 540 0.96
15 560 0.83
15 580 0.78
15 600 0.68
15 620 0.57
15 640 0.48
15 660 0.4
15 680 0.35
15 700 0.73
15 720 0.5
15 740 0.21
15 760 0.52
15 780 0.23
15 800 0.5
15 820 1.45
15 840 0.21
15 860 0.14
15 900 0.63
15 940 1.71
15 980 9.9
15 1020 2.56
15 1060 0.32
15 1100 0.31
15 1150 0.36
15 1200 0.21
15 1250 0.15
15 1300 0.08
15 1350 0.08
25 400 188.4
25 450 28.17
25 500 369.64
25 520 280.5
25 540 8.03
25 560 4.66
25 580 9.21
25 600 13.97
25 620 13.36
25 640 8.28
25 660 368.02
25 680 304.22
25 700 38.83
25 720 70.18
25 740 6.48
25 760 2.62
25 780 1.38
25 800 2.22
25 820 1.64
25 840 0.7
25 860 0.45
25 900 1.07
25 940 27.94
25 980 1068.64
25 1020 1.44
25 1060 0.52
25 1100 0.03
25 1150 0.64
25 1200 0
25 1250 0
25 1300 0
25 1350 0
30 400 226.74
30 450 35.11
30 500 356.27
30 520 270.5
30 540 39.96
30 560 32.85

Solution

  • For example, if testing with "2.81h", would you expect the following result?

    Convert: 02:48:36

    If it is correct, try this:

    let
        Source = DataSource
        HoursColumn = Table.AddColumn(Source, "TimeFormatDuration", each Duration.From([Duration,h] * #duration(0, 0, 1, 0)))
    in
        HoursColumn
    

    And (from Davidebacci's comment):

    Table.AddColumn(#"Added Custom", "Custom.1", each Duration.From([Duration] * #duration(0, 1, 0, 0))