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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
cosmicyes
Helper II
Helper II

Turn a String into a Date

I got some data from a very old ERP-System.
The date in the csv-file is this way:

* 80520 for May 8 2020

* 110520 for May 11 2020

So the string can have 5 or 6 characters.
I solved it myself using some string-operations in DAX but this is VERY complicated and I need to do this very often.

Is there an easier way?

I tried to add some lines of my code in a previos post but it was marked as spam and I don´t know why 😞

1 ACCEPTED SOLUTION
moizsherwani
Continued Contributor
Continued Contributor

Not sure why the DAX formula you created is complicated. See below which works fine for your sample data. You can just create this as a calculuated column.

Date =
VAR YearVal =
    "20" & RIGHT ( 'Table'[ERP System], 2 )
VAR MonthVal =
    LEFT ( RIGHT ( 'Table'[ERP System], 4 ), 2 )
VAR DateVal =
    LEFT ( 'Table'[ERP System], LEN ( 'Table'[ERP System] ) - 4 )
RETURN
    DATE ( YearVal, MonthVal, DateVal )

 

moizsherwani_0-1631970492635.png

 

 

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

View solution in original post

5 REPLIES 5
CNENFRNL
Community Champion
Community Champion

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WsjAwNTJQitWJVjI0hDBjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Old = _t]),

    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Old", Int64.Type}}),
    #"Converted Date" = Table.AddColumn(#"Changed Type", "Date_PQ", each Date.From(Number.ToText([Old], "0/00/00"), "en-GB"))
in
    #"Converted Date"

Screenshot 2021-09-18 160512.png


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!

is this M? Unfortunately I am not familiar with M yet. But thank you!

moizsherwani
Continued Contributor
Continued Contributor

Not sure why the DAX formula you created is complicated. See below which works fine for your sample data. You can just create this as a calculuated column.

Date =
VAR YearVal =
    "20" & RIGHT ( 'Table'[ERP System], 2 )
VAR MonthVal =
    LEFT ( RIGHT ( 'Table'[ERP System], 4 ), 2 )
VAR DateVal =
    LEFT ( 'Table'[ERP System], LEN ( 'Table'[ERP System] ) - 4 )
RETURN
    DATE ( YearVal, MonthVal, DateVal )

 

moizsherwani_0-1631970492635.png

 

 

Thanks,

Moiz
Was I able to answer your question? Mark my post as a solution to help others. Kudos if you liked the solution.

This looks MUCH easier than my solution. Thank you, that´s great!

aj1973
Community Champion
Community Champion

Hi @cosmicyes 

Did you try to use Power Query? And even with DAX why do you have to do it so often?

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors