Forum Discussion
Anonymous
5 years agoNot 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 colu...
- 5 years ago
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:
It can be used in incremental refresh.
Best Regards,
KellyDid I answer your question? Mark my post as a solution!
Anonymous
5 years agoNot 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 ) )
)
)
)