Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Convert table from number to date

Hello! I'm trying to convert this table into a date:

ivoferrari_1-1649437532363.png

It has values as dd/mm/yy, but its not formatted propperly, how can I change them to make them look like 1/02/22, for example?

1 ACCEPTED SOLUTION
serpiva64
Super User
Super User

Hi,

you can create a custom column

(if Text.Length([Column1]) = 5 then Text.Start([Column1],1)&"/"&Text.Middle([Column1],1,2) else Text.Start([Column1],2)&"/"&Text.Middle([Column1],2,2))&"/"&Text.End([Column1],2)

serpiva64_0-1649438943460.png

and then change type to Date

 

If this post is useful to help you to solve your issue consider giving the post a thumbs up 

 and accepting it as a solution !

 

View solution in original post

5 REPLIES 5
tackytechtom
Super User
Super User

Hi @Anonymous ,

 

I'd probably try to fix it in Power Query:

tomfox_0-1649438903392.png


Add a new custom column and use the following code:

= Table.AddColumn(#"Changed Type", "Custom", each Text.Insert ( Text.Insert ( Text.From ([Date]), Text.Length([Date]) - 2, "/"), Text.Length([Date]) - 4, "/"))

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMjJSitWJVjKyNDAxtIQwDQwNjQzBTGMDYyMDpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Text.Insert ( Text.Insert ( Text.From ([Date]), Text.Length([Date]) - 2, "/"), Text.Length([Date]) - 4, "/"))
in
    #"Added Custom"

 

Note, the column needs to be in text format for the code to function. Also, the code will only work if the data is either in the format DDMMYY or DMMYY. If your data happens to be DDMYY or DMYY, it won't work.

 

Let me know, if this helped to solve your issue 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Anonymous
Not applicable

Hello! Trying to do it as your first method shows me this:

ivoferrari_0-1649440127313.png

And if I expand it for "Custom" It shows me an error

Hi @Anonymous ,

 

Interesting... Does it work this way? 🙂

 

tomfox_0-1649440503891.png

 

Code

Text.Insert ( Text.Insert ( Text.From ([Date]), Text.Length([Date]) - 2, "/"), Text.Length([Date]) - 4, "/")

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/

 

 



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

serpiva64
Super User
Super User

Hi,

you can create a custom column

(if Text.Length([Column1]) = 5 then Text.Start([Column1],1)&"/"&Text.Middle([Column1],1,2) else Text.Start([Column1],2)&"/"&Text.Middle([Column1],2,2))&"/"&Text.End([Column1],2)

serpiva64_0-1649438943460.png

and then change type to Date

 

If this post is useful to help you to solve your issue consider giving the post a thumbs up 

 and accepting it as a solution !

 

Anonymous
Not applicable

Thanks! It worked just fine!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.