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
Frixel
Post Prodigy
Post Prodigy

convertir marca de tiempo

Hola

Tengo en mi archivo un colomn con TimeStamps como este.

1.png

como usted ve la fecha es una mezcla de 8 dígitos, 9 dígitos o 10 dígitos.

Quiero tratar de hacer Colomn's Date & Time Colomnn

¿Cómo puedo hacer coloms separados con fecha y hora de esto?

1 ACCEPTED SOLUTION

@Frixel Pruebe lo siguiente:

Date Column = 
    VAR __Date = SUBSTITUTE(LEFT([Column1],SEARCH(" ",[Column1],,0)),"(","")
    VAR __FirstHyphen = SEARCH("-",__Date,,0)
    VAR __SecondHyphen = SEARCH("-",__Date,__FirstHyphen+1,0)
    VAR __Day = LEFT(__Date,SEARCH("-",__Date,,0)-1)
    VAR __Month = MID([Column1],__FirstHyphen+2,__SecondHyphen - __FirstHyphen - 1)
    VAR __Year = RIGHT(__Date,LEN(__Date) - __SecondHyphen)
    VAR __NewDate = __Month & "-" & __Day & "-" & __Year
RETURN
    __NewDate

PBIX se adjunta debajo de sig. Tabla (17a)


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

13 REPLIES 13
CNENFRNL
Community Champion
Community Champion

@Frixel IMHO, es un peso ligero para hacer frente a Power Query, ya que hay un tipo de fecha específico llamado datetime para contener estos datos. Pls probar el código M a continuación,

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0jDTNbLUNTIwMlAwsLAyMLIyMdFUitUBShjqmkPFza2MgVKWQPFYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    Trans = Table.TransformColumns(Source, {{"Column1", each Text.Remove(_, {"(", ")"})}}),
    #"Changed Type" = Table.TransformColumnTypes(Trans,{{"Column1", type datetime}}),
    Split = Table.TransformColumns(#"Changed Type", {"Column1", each [Date = DateTime.Date(_), Time = DateTime.Time(_)]}),
    #"Expanded Column1" = Table.ExpandRecordColumn(Split, "Column1", {"Date", "Time"}, {"Date", "Time"})
in
    #"Expanded Column1"

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

amitchandak
Super User
Super User

@Frixel , ¿tiene toda la fecha y hora en formato dd-MM .becasue en ese caso sólo necesita eliminar ( y ) y se puede obtener la fecha con esta configuración

https://community.powerbi.com/t5/Desktop/How-to-apply-UK-date-format-dd-mm-yyyy-in-Date-slicer/td-p/...

Greg_Deckler
Super User
Super User

@Frixel ¿Reemplazar el ( ) con blanco (nada) y luego dividir en el espacio?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hola @Greg_Deckler

DAX es esto?

1.png

@Frixel En Power Query, haga lo siguiente:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W0jDTNbLUNTIwMlAwsLAyMLIyMdFUitUBShjqmkPFza2MgVKWQPFYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","(","",Replacer.ReplaceText,{"Column1"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",")","",Replacer.ReplaceText,{"Column1"}),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Replaced Value1", "Column1", Splitter.SplitTextByDelimiter(" ", QuoteStyle.Csv), {"Column1.1", "Column1.2"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Column1.1", type date}, {"Column1.2", type time}})
in
    #"Changed Type1"

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Frixel No, eso es Power Query.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler

Los ( ) siguen ahí parados.

1.png

@Frixel OK, si lo estás haciendo a través de DAX, entonces sería:

Date Column = 
  SUBSTITUTE(LEFT([Timestamp],SEARCH(" ",[Timestamp],,0)),"(","")

Time Column = 
  SUBSTITUTE(RIGHT([Timestamp],LEN([Timestamp]) - SEARCH(" ",[Timestamp],,0)),")","")


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler

Genial, ahora confiere la hora y la fecha.

Pero...

El problema es que la fecha se invierte, si sabes a lo que me refiero.

1a fila 1a colomn 1 de julio de 2020, etc.

1.png

@Frixel Pruebe lo siguiente:

Date Column = 
    VAR __Date = SUBSTITUTE(LEFT([Column1],SEARCH(" ",[Column1],,0)),"(","")
    VAR __FirstHyphen = SEARCH("-",__Date,,0)
    VAR __SecondHyphen = SEARCH("-",__Date,__FirstHyphen+1,0)
    VAR __Day = LEFT(__Date,SEARCH("-",__Date,,0)-1)
    VAR __Month = MID([Column1],__FirstHyphen+2,__SecondHyphen - __FirstHyphen - 1)
    VAR __Year = RIGHT(__Date,LEN(__Date) - __SecondHyphen)
    VAR __NewDate = __Month & "-" & __Day & "-" & __Year
RETURN
    __NewDate

PBIX se adjunta debajo de sig. Tabla (17a)


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Gracias

Parece que ahora tengo el formato date correcto.

1.png

¿Puedo ahora también mover la fecha y hora de Colomns en otro lugar?

No puedo encontrar una opción para mover colomns a otro lugar

@Frixel No estoy seguro de lo que quieres decir con eso. Las columnas calculadas DAX siempre se colocan al final de una tabla.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Frixel Tratar:

Date Column = 
    VAR __Date = SUBSTITUTE(LEFT([Column1],SEARCH(" ",[Column1],,0)),"(","")
    VAR __FirstHyphen = SEARCH("-",__Date,,0)
    VAR __SecondHyphen = SEARCH("-",__Date,__FirstHyphen+1,0)
    VAR __Day = LEFT(__Date,SEARCH("-",__Date,,0)-1)
    VAR __Month = MID([Column1],__FirstHyphen+2,__SecondHyphen - __FirstHyphen - 1)
    VAR __Year = RIGHT(__Date,LEN(__Date) - __SecondHyphen)
    VAR __NewDate = __Month & "-" & __Day & "-" & __Year
RETURN
    __NewDate

PBIX se adjunta debajo de sig. Tabla (17a)


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.