Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
2 years ago

Data Transform in Power BI to Convert Time or date/time field to total number of minutes?

Hello Power World, 

 

I am trying to determine the throughput of a particular data transfer I am doing from on-premises to SharePoint Online.  After the import, I can extract an excel sheet of everything transferred and the amount of time each item took to transfer over.  I import this report into PowerBI.  One field is a time value field showing "hh:mm:ss".  


I would like to create a second column that expresses that in total number of minutes.

 

let
Source = Excel.Workbook(File.Contents("C:\Users\Me\OneDrive\myAggregate Summary Report -BATCH-1.xlsx"), null, true),
#"Aggregate Summary Report (10)_Sheet" = Source{[Item="Aggregate Summary Report (10)",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(#"Aggregate Summary Report (10)_Sheet", [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Duration", type time}}),
#"Extracted Time" = Table.TransformColumns(#"Changed Type",{}),
#"Changed Type1" = Table.TransformColumnTypes(#"Extracted Time",{{"Migrated bytes", Int64.Type}, {"Total bytes", Int64.Type}, {"Migrated items", Int64.Type}, {"Total to be migrated items", Int64.Type}, {"Total scanned items", Int64.Type}, {"Items not migrated", Int64.Type}, {"Total GB", Int64.Type}, {"Migrated GB", Int64.Type}}),
#"durationMin" = Table.AddColumn(#"Changed Type", {{"durationMin", Int64.Type}, each Duration.TotalMinutes(Duration.From([Duration]))
in
#"durationMin"

 

I've looked at various posts and documents elsewhere, but I can't get this to work either because of syntax errors or too few arguments to a function.  I am a novice when it comes to DAX

 

Thanks!

Signed, 

Baffled and bewildered!

 

2 Replies

  • Time is stored as a fraction of a day. So to express the value in Minutes, merely multiply by 1440 (or 24*60).

    If you wanted time in seconds, you would multiply by 86,400.

     

    Minutes = [Time]*1440

     

    Note: The above formula is DAX and you would use it as an added column in Power BI.

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    No, Excel stores time as a fraction of the day; the Data Model stores it as a proper datetime value. So unless you convert that value to a decimal number first, you can't get the minutes by x 1440 (which is easy to do though). In your case,


    Table.AddColumn(PriorStepOrTableName, "Elapsed Time", 

    each Duration.TotalMinutes(Duration.From(DateTime.From([Duration]))))

     

    Your formula is erroring because you have only "{}" for your  parameters in your #"Extracted Time step. Also, your Table. AddColumn should be written as

     

    Table.AddColumn(table as table, newColumnName as text, columnGenerator as function, optional columnType as nullable type) as table

    --Nate