text CYYMMDD to Date MMDDYYYY

sricks

New Member
Joined
Mar 25, 2015
Messages
7
I'm working with AS400 information that is bring dates into my query formatted as text CYYMMDD. I need this to be converted to a date. I cleaned up the data to make sure there was no other trailing spaces, and tried Date.Fromtext, but I'm still getting an error. Most of the help I am stumbling across is relating to excel formulas that aren't easily "translated" to a Power Query, and I believe that I am missing a step but have no clue which step I am missing. Any help is appreciated!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
I don't use Power BI -- will a formula do?

[Table="width:, class:grid"][tr][td]Row\Col[/td][td]
A​
[/td][td]
B​
[/td][td]
C​
[/td][/tr][tr][td]
1​
[/td][td]0911231[/td][td]
12/31/1991​
[/td][td]B1: =--TEXT(19 + LEFT(A1) & MID(A1, 2, 6), "0000-00-00")[/td][/tr]
[tr][td]
2​
[/td][td]1150602[/td][td]
06/02/2015​
[/td][td][/td][/tr]
[/table]
 
Upvote 0
Hi sricks :-)

There are many ways to do this but this one is using User Interface only (M language knowledge is not necessary).

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Tabela1"]}[Content],
    SplitCol1 = Table.SplitColumn(Source,"dates",Splitter.SplitTextByPositions({0, 1}, false),{"dates.1", "dates.2"}),
    RemCol = Table.RemoveColumns(SplitCol1,{"dates.1"}),
    SplitCol2 = Table.SplitColumn(RemCol,"dates.2",Splitter.SplitTextByRepeatedLengths(2),{"dates.2.1", "dates.2.2", "dates.2.3"}),
    CombineCols = Table.CombineColumns(SplitCol2,{"dates.2.2", "dates.2.3", "dates.2.1"},Combiner.CombineTextByDelimiter("/", QuoteStyle.None),"Text dates"),
    ChType = Table.TransformColumnTypes(CombineCols, {{"Text dates", type date}}, "en-US")
in
    ChType

Of course you can use your own data source instead of Excel.CurrentWorkbook.
Imkef's advice is also good way :-)

Regards
 
Upvote 0

Forum statistics

Threads
1,226,695
Messages
6,192,475
Members
453,726
Latest member
JoeH57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top