Text "number" value to date value?

scott_86_

New Member
Joined
Sep 27, 2018
Messages
40
Office Version
  1. 365
Platform
  1. Windows
Hi,

Referencing the below image, in PQ, is it possible to transform (or create a new column) from the figures in the below images?

For example, the top text "number" string is 230831 (which represents YYMMDD). Can this be transformed to a date vale of DD-MM-YY (I'm in Australia!)?

For context, this list of numbers in the image have been taken from PDF file names of training certificates.

PQ Date question.PNG
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
In the advanced editor, use the following code to get the result below.
Change the following names in the code with your actual values.
Table name: Table1
Column name: Value

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Convert = Table.TransformColumns(Source, {"Value", each Date.ToText(Date.FromText(Text.From(_), [Format="yyMMdd"]), [Format="dd-MM-yy"]) })
in
    Convert

The Table.TransformColumns() function takes the source table, and transforms the column values by the provided column name and the column transformation function.

In the transformation function, basically, the inner function, Date.FromText(), converts the text value by using the given format, yyMMdd. The second function, Date.ToText(), transforms the calculated value to the requested format, dd-MM-yy.
The Text.From() function makes sure the source data value is actually text in case you don't have a type change step.

ValueValue
23083131-08-23
23071212-07-23
23032727-03-23
23020303-02-23
22091010-09-22
21121515-12-21
19103131-10-19
19091717-09-19
19051515-05-19
18081717-08-18
18012222-01-18
13032727-03-13
12011111-01-12
11102121-10-11
11071919-07-11
10121717-12-10
10050303-05-10
09120303-12-09
09120303-12-09

Instead of using the TransformColumns() function to make the change on the actual column, you can also use Table.AddColumn() function to create a new column. However, if you won't need the original column and if you are going to delete it anyway, then this will be only an extra step. Here is the AddColumn() version. Basically the same transformation function is used to create the new column except you need to provide the column name this time.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    AddColumn = Table.AddColumn(Source, "Custom", each Date.ToText(Date.FromText(Text.From([Value]), [Format="yyMMdd"]), [Format="dd-MM-yy"]))
in
    AddColumn
 
Upvote 0

Forum statistics

Threads
1,223,897
Messages
6,175,270
Members
452,628
Latest member
dd2

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