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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
wangjuan303
Helper III
Helper III

How to change date type to YYYYMMDD, need from 1/1/2021 change to 20210101.

I need change a date column to a Whole number  column, whole number column should show YYYYMMDD format, I need do it with M code, I know how to step by step do it, but it too much step, Is here anyone know the easy way to change it. Thank you .

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @wangjuan303 

The simplest way I can think of is something like this:

Number.From(Date.ToText([Date],"yyyyMMdd"))

 

Here is a complete sample query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJUitWJVjLWNzRA8Awt9S2APAMDpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Date", type date}}, "en-NZ"),
    #"Added Custom" = Table.AddColumn(#"Changed Type with Locale", "Date Integer", each Number.From(Date.ToText([Date],"yyyyMMdd")), Int64.Type)
in
    #"Added Custom"

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

3 REPLIES 3
RandomWalker
Frequent Visitor

There actually is a simple way to achieve this. In the Model View, select the date field that you would like to format. Then in the Properties pan, you'll find a "Date time format" dropdown menu. Select "Custom" and put "yyyymmdd" in for box below. This shuold gives you the desired YYYYMMDD format.Screenshot 2024-08-28 at 4.57.44 PM.png

iabarraganc
Helper I
Helper I

Another trick. You can use this formula

idDate = Table.AddColumn(RenombraFecha, "ID_DATE", each 10000 * Date.Year([DATE_COLUMN]) + 100 * Date.Month([DATE_COLUMN]) + Date.Day([DATE_COLUMN]), Int64.Type),
OwenAuger
Super User
Super User

Hi @wangjuan303 

The simplest way I can think of is something like this:

Number.From(Date.ToText([Date],"yyyyMMdd"))

 

Here is a complete sample query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJUitWJVjLWNzRA8Awt9S2APAMDpdhYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type with Locale" = Table.TransformColumnTypes(Source, {{"Date", type date}}, "en-NZ"),
    #"Added Custom" = Table.AddColumn(#"Changed Type with Locale", "Date Integer", each Number.From(Date.ToText([Date],"yyyyMMdd")), Int64.Type)
in
    #"Added Custom"

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

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.