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
Anonymous
Not applicable

Create a YYYYMMDD Column without breaking Query Folding

So I have a year column that comes in as a number (2021). I also have a month column that comes in as a number (2).

 

How can I create a column that will use the year column, but pad the month column with a 0, and then add in a default 01 for the day?

 

So take February 1st, 2021 for example. My year column would be the number 2021 and my month column would be the number 2. 

 

How can I create a column that would return 20210201 as a number without breaking query folding? Is it possible?

 

I tried Text.PadStart(Text.From) and then making that custom column a number, but query editor still thinks it's a text column even though it says number.  

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

Take below M codes:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMlDSUTJUitUBcwxBHAMUnhEyz1IpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, Month = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Month", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "FullDate", each [Year] * 10000 + [Month] * 100 + 01),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"FullDate", Int64.Type}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom", each if Text.Length(Text.From([Month]))=1  then Text.PadStart(Text.From([Month]),2,"0") else Text.From([Month])),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.1", each Text.From([Year])&[Custom]&"01"&"T00:00:00"),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Custom.2", each DateTime.FromText([Custom.1]))
in
    #"Added Custom3"

 

Finally you will see:

v-kelly-msft_0-1612343456042.png

 

 

v-kelly-msft_1-1612343479039.png

 

It can be used in incremental refresh.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

 

View solution in original post

5 REPLIES 5
v-kelly-msft
Community Support
Community Support

Hi  @Anonymous ,

 

Take below M codes:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMlDSUTJUitUBcwxBHAMUnhEyz1IpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, Month = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Month", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "FullDate", each [Year] * 10000 + [Month] * 100 + 01),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"FullDate", Int64.Type}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type1", "Custom", each if Text.Length(Text.From([Month]))=1  then Text.PadStart(Text.From([Month]),2,"0") else Text.From([Month])),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Custom.1", each Text.From([Year])&[Custom]&"01"&"T00:00:00"),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Custom.2", each DateTime.FromText([Custom.1]))
in
    #"Added Custom3"

 

Finally you will see:

v-kelly-msft_0-1612343456042.png

 

 

v-kelly-msft_1-1612343479039.png

 

It can be used in incremental refresh.

 

Best Regards,
Kelly

Did I answer your question? Mark my post as a solution!

 

 

PhilipTreacy
Super User
Super User

Hi @Anonymous 

Not clear if you need this in PQ or DAX.  Download a sample PBIX with PQ code

This code will create a column in PQ that is type Whole Number, this will get added into the Data Model too

 

= Table.AddColumn(#"Changed Type", "FullDate", each [Year] * 10000 + [Month] * 100 + 01)

 

ggassss.png

This is the full example query

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMlDSUTJUitUBcwxBHAMUnhEyz1IpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, Month = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Month", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "FullDate", each [Year] * 10000 + [Month] * 100 + 01),
    #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"FullDate", Int64.Type}})
in
    #"Changed Type1"

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

@PhilipTreacy Thanks this is definitely what I'm looking for. I'm not able to test it at the moment. That column will definitely work. My only hesitation is if the last step in your proposed code would break query folding? This would be used to implement incremental refresh so I can't have it break query fold. 

Hi @Anonymous 

You can remove the Change Type step.  If you need to you can set the Data type inside the Data Model after data is loaded into it

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMlDSUTJUitUBcwxBHAMUnhEyz1IpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Year = _t, Month = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Year", Int64.Type}, {"Month", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "FullDate", each [Year] * 10000 + [Month] * 100 + 01)
in
    #"Added Custom"

 

Not sure where you are loading data from so not sure if a Change Type would break query folding.  You can test and see?  Right click the step and see if View Native Query is available.  If it is then QF is ok.

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Anonymous
Not applicable

Hello @Anonymous ,
You can use the below DAX formula for a calculated column in the calendar table.
YearMonthDay =
VALUE (
CONCATENATE (
FORMAT ( 'Date'[Date], "YYYY" ),
CONCATENATE (
( RIGHT ( "0" & MONTH ( 'Date'[Date] ), 2 ) ),
( RIGHT ( "0" & DAY ( 'Date'[Date] ), 2 ) )
)
)
)

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