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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Peter_Yaacoub
Frequent Visitor

Date Column Returning null

Hi everyone!

I am  trying to create a date column based on my YearDate column (snapshot below). If YearDate Column is Current Year -1, I want to replace it  with [Merged], otherwise replace with [Merged.1].

 

Unfortunately the formula I am using returns null. Your help is much appreciated.

 

Thanks,

Peter

 

Peter_Yaacoub_0-1655458312255.png

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Insert this statement where #"Changed Type" is your previous step

= Table.ReplaceValue(#"Changed Type",each [YearDate],each if Date.Year([YearDate])=Date.Year(DateTime.FixedLocalNow())-1 then [Merged]
else [Merged.1],Replacer.ReplaceValue,{"YearDate"})

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ3NtQ3MjAyVNJRcgRiJyAGc2N1UCWdgdgFm6QRUNAViN0gkkYYku5A7IFL0hOIvXBJegOxD1wyFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [YearDate = _t, Merged = _t, Merged.1 = _t, Year = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"YearDate", type date}, {"Merged", type text}, {"Merged.1", type text}, {"Year", Int64.Type}}),
    Custom1 = Table.ReplaceValue(#"Changed Type",each [YearDate],each if Date.Year([YearDate])=Date.Year(DateTime.FixedLocalNow())-1 then [Merged]
else [Merged.1],Replacer.ReplaceValue,{"YearDate"})
in
    Custom1

View solution in original post

1 REPLY 1
Vijay_A_Verma
Super User
Super User

Insert this statement where #"Changed Type" is your previous step

= Table.ReplaceValue(#"Changed Type",each [YearDate],each if Date.Year([YearDate])=Date.Year(DateTime.FixedLocalNow())-1 then [Merged]
else [Merged.1],Replacer.ReplaceValue,{"YearDate"})

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ3NtQ3MjAyVNJRcgRiJyAGc2N1UCWdgdgFm6QRUNAViN0gkkYYku5A7IFL0hOIvXBJegOxD1wyFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [YearDate = _t, Merged = _t, Merged.1 = _t, Year = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"YearDate", type date}, {"Merged", type text}, {"Merged.1", type text}, {"Year", Int64.Type}}),
    Custom1 = Table.ReplaceValue(#"Changed Type",each [YearDate],each if Date.Year([YearDate])=Date.Year(DateTime.FixedLocalNow())-1 then [Merged]
else [Merged.1],Replacer.ReplaceValue,{"YearDate"})
in
    Custom1

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors