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.
Hola buenos días.
Necesito convertir el formano hh:mm:ss a ss. A pesar de haber estado buscando por internet y en el foro posibles soluciones a mi problema, ninguna de las encontradas me da solución.
Os cuento:
El dato en el origen viene expresado en el formato archivo hh:mm:ss, y cuando lo importo a power bi, me lo importa en el formato datetime "31/12/1899 0:00:00", por lo que no me permite realizar cálculos. Desde el editor avanzado modifico el formato datetime a time y ahora sí tengo el formato hh:mm:ss., pero a partir de aquí no encuentro la manera de pasarlos a segundos.
Buscando por Internet, se encuentran una solución utilizando las funciones Text.BerofeDelimeter, Text.AfterDelimeter y Text.BetweenDelimeter, pero no me funcionan. La expresión que indicaban concretamente es la siguiente.
Number.FromText(Text.BeforaDelimiter([CAMPO],":"))*3600 + Number.FromText(Text.AfterDelimeter([CAMPO], ":" , ":", 0 , 0))*60 + Number.FromText(Text. BetweenDelimiter([CAMPO], ":", 1))
Igual esta función opera con campos en formato texto, por lo que lo convertí en texto, pero al hacerlo pierdo los segundos, se convierte en "HH:MM".
Otra de las opciones que se va a intentar ser separar en las columnas en función limitada der ":", pero la columna que correspondería a los segundos la pone en blanco, sin datos.
¿Alguna solución a este problema?
Muchas gracias
Solved! Go to Solution.
It seems like your data are actually durations (length of call). I made some sample data in Excel using the same format string. Here is a way to convert your values to a duration. I chose minutes in decimal form, but you can use Duration.TotalSeconds if you prefer. You can just look at the function in the #"Added Custom" step, where the duration between your time values and midnight (#time(0,0,0)) is calculated. Having a decimal number for your call durations will make your calculations easier.
let
Source = Excel.Workbook(File.Contents("C:\Test\TimeTest.xlsx"), null, true),
Sheet3_Sheet = Source{[Item="Sheet3",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet3_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Time of Conversation", type time}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Call Duration", each Duration.TotalMinutes([Time of Conversation] - #time(0,0,0))),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Call Duration", type number}})
in
#"Changed Type1"
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
It seems like your data are actually durations (length of call). I made some sample data in Excel using the same format string. Here is a way to convert your values to a duration. I chose minutes in decimal form, but you can use Duration.TotalSeconds if you prefer. You can just look at the function in the #"Added Custom" step, where the duration between your time values and midnight (#time(0,0,0)) is calculated. Having a decimal number for your call durations will make your calculations easier.
let
Source = Excel.Workbook(File.Contents("C:\Test\TimeTest.xlsx"), null, true),
Sheet3_Sheet = Source{[Item="Sheet3",Kind="Sheet"]}[Data],
#"Promoted Headers" = Table.PromoteHeaders(Sheet3_Sheet, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Time of Conversation", type time}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Call Duration", each Duration.TotalMinutes([Time of Conversation] - #time(0,0,0))),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Call Duration", type number}})
in
#"Changed Type1"
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Hola @JUAN_1969 ,
Creo que la expresión que dices que encontraste la tienes girada.
Corregida sería:
= Table.AddColumn(Source, "Custom", each Number.FromText(Text.BeforeDelimiter([#"hh:mm:ss"],":"))*3600 + Number.FromText(Text.BetweenDelimiters([#"hh:mm:ss"], ":" , ":", 0 , 0))*60 + Number.FromText(Text.AfterDelimiter([#"hh:mm:ss"], ":", 1)))
Saludos,
Hola Payeras, gracias por tu respuesta, pero no me funciona. Por lo que veo en tu ejemplo, tu campo hh:mm:ss lo tienes en formato texto y a mí no me deja. Quizás el problema esté en el origen del dato. Te voy a mostrar paso a paso desde el Excel con un pequeño ejemplo como me lo importa.
El campo de tiempo, en el Excel, es formato personalizado [hh]\:mm\:ss
y cuando lo importo a power bi lo hace de la siguiente manera
y por mucho que lo intento, no consigo que pase a formato hh:mm:ss manteniendo todos los datos.
En el editor esto es lo que me refleja
let
Origen = Excel.Workbook(File.Contents("C:\Users\usuario\Desktop\hh_mm_ss.xlsx"), null, true),
Hoja1_Sheet = Origen{[Item="Hoja1",Kind="Sheet"]}[Data],
#"Encabezados promovidos" = Table.PromoteHeaders(Hoja1_Sheet, [PromoteAllScalars=true]),
#"Tipo cambiado" = Table.TransformColumnTypes(#"Encabezados promovidos",{{"Fecha", type date}, {"Tiempo de Conversación", type datetime}})
in
#"Tipo cambiado"
El tipo datetime, lo puedo cambiar a time, pero a partir de ahí ya me encuentro con los problemas que indicaba en el comienzo del post.
Muchas gracias por la ayuda.
If you extract the text after the " " delimiter (space), you should then be able to convert it to type Time including the seconds.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Hola mahoneypat lo he intentado y sale la columna en blanco
= Table.AddColumn(#"Tipo cambiado", "Texto después del delimitador", each Text.AfterDelimiter(Text.From([Tiempo de Conversación], "es-ES"), ":", 1), type text)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.