Power BI中如何将小时、分钟、秒转换为分钟?

How to convert hours, minutes, second in PowerBI to minutes?

大家好,

我有一个名为 Table1 的 table,其中有一列显示学生完成考试所用的时间(如上面的屏幕截图所示)。我可以知道如何将列转换为分钟吗?基本上需要将 hrs(如果存在)转换为分钟并将 sec 转换为分钟。

为简化输出,如果sec大于或等于30秒,则计为1分钟,否则忽略sec。我还是 PowerBI 的新手,非常感谢任何帮助!

建议答案的输出

您可以在 table 中执行以下步骤以获得所需的输出-

高级查询编辑器代码

let
    //... your previous steps,
    // Change the PREVIOUS STEP NAME accordingly in the NEXT line


    #"Replaced Value1" = Table.ReplaceValue(#"PREVIOUS STEP NAME"," hrs","hrs",Replacer.ReplaceText,{"Time Taken"}),
    #"Replaced Value" = Table.ReplaceValue(#"Replaced Value1"," min","min",Replacer.ReplaceText,{"Time Taken"}),
    #"Replaced Value2" = Table.ReplaceValue(#"Replaced Value"," sec","sec",Replacer.ReplaceText,{"Time Taken"}),
    #"Duplicated Column" = Table.DuplicateColumn(#"Replaced Value2", "Time Taken", "Time Taken - Copy"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Duplicated Column", "Time Taken - Copy", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Time Taken - Copy.1", "Time Taken - Copy.2", "Time Taken - Copy.3"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Time Taken - Copy.1", type text}, {"Time Taken - Copy.2", type text}, {"Time Taken - Copy.3", type text}}),
    #"Replaced Value3" = Table.ReplaceValue(#"Changed Type1",null,"",Replacer.ReplaceValue,{"Time Taken - Copy.1", "Time Taken - Copy.2", "Time Taken - Copy.3"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value3", "hrs", each if Text.PositionOf([#"Time Taken - Copy.1"],"hrs") > 0 then Text.Replace([#"Time Taken - Copy.1"],"hrs","")
else if Text.PositionOf([#"Time Taken - Copy.2"],"hrs") > 0 then Text.Replace([#"Time Taken - Copy.2"],"hrs","")
else if Text.PositionOf([#"Time Taken - Copy.3"],"hrs") > 0 then Text.Replace([#"Time Taken - Copy.3"],"hrs","")
else "0"),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "min", each if Text.PositionOf([#"Time Taken - Copy.1"],"min") > 0 then Text.Replace([#"Time Taken - Copy.1"],"min","")
else if Text.PositionOf([#"Time Taken - Copy.2"],"min") > 0 then Text.Replace([#"Time Taken - Copy.2"],"min","")
else if Text.PositionOf([#"Time Taken - Copy.3"],"min") > 0 then Text.Replace([#"Time Taken - Copy.3"],"min","")
else "0"),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "sec", each if Text.PositionOf([#"Time Taken - Copy.1"],"sec") > 0 then Text.Replace([#"Time Taken - Copy.1"],"sec","")
else if Text.PositionOf([#"Time Taken - Copy.2"],"sec") > 0 then Text.Replace([#"Time Taken - Copy.2"],"sec","")
else if Text.PositionOf([#"Time Taken - Copy.3"],"sec") > 0 then Text.Replace([#"Time Taken - Copy.3"],"sec","")
else "0"),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"Time Taken - Copy.1", "Time Taken - Copy.2", "Time Taken - Copy.3"}),
    #"Changed Type2" = Table.TransformColumnTypes(#"Removed Columns",{{"hrs", Int64.Type}, {"min", Int64.Type}, {"sec", Int64.Type}}),
    #"Added Custom3" = Table.AddColumn(#"Changed Type2", "final_minutes", each ([hrs]*60) + [min] + (if [sec]>=30 then 1 else 0))
in
    #"Added Custom3"

样本输出-