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

NEW date column based on condition

 

Hi, 

I have 2 dates column and I want to create  a new date column based on the Last PODdate and FirstPOD date. 

 

The logic is as follows: 

New PoDDateColumn= If the FirstPOD date has a value use FirstPod Date as a column. If there is no value in the first POD date use the Last PodDate. Any Help would be appreciated? 

talal_007_1-1666562604119.png

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

I solved this problem on my own using a very simple trick. I trimmed the dates and then inserted null in the blanks. After inserting "null" in place blanks. I was able to get what I wanted. using the same coalesce function using ??

 

= Table.AddColumn(#"Changed Type", "Final_PodDate", each [FirstPODDate]??[LastPODDate]) 

View solution in original post

Yep, which is why I said above, you'll need to convert blanks to nulls. 

Glad you got it worked out.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

I solved this problem on my own using a very simple trick. I trimmed the dates and then inserted null in the blanks. After inserting "null" in place blanks. I was able to get what I wanted. using the same coalesce function using ??

 

= Table.AddColumn(#"Changed Type", "Final_PodDate", each [FirstPODDate]??[LastPODDate]) 

Yep, which is why I said above, you'll need to convert blanks to nulls. 

Glad you got it worked out.

 

Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x
hannibalmads
Advocate III
Advocate III

Add a custom column where you concatenate the two fields and then extract the first 8 characters (assuming that the data types are text)

Text.Start(Text.Combine({[FirstPODDate], [LastPODDate]}, ""), 8 )

 

If the data types are numeric then the coalesce should work

mahoneypat
Microsoft Employee
Microsoft Employee

You can add a custom column in the query editor to do that. You could use if ... then ... else syntax, but it is easier to use the coalesce syntax in this case. Just click on the Add Column tab, then Custom Column, and enter the expression below into the pop-up box.

 

= [FirstPODdate] ?? [LastPODdate]

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Okay I did that and it gives me only the FirstPodDates as shown below and Power Query is also given 

Dates not being read properly is that going to be an issue? 

i will use the modified date column as the date connector for the date dimmension table. 

Any hints would be great! 

= Table.AddColumn(#"Changed Type", "Final_PodDate", each [FirstPODDate]??[LastPODDate])

 

talal_007_0-1666570466585.png

 

Anonymous
Not applicable

Still am facing the issue after using the coalesce function

talal_007_1-1666573756849.png

 

 

talal_007_0-1666573665622.png

 

You'll likely need to convert blanks to nulls first for the coalesce to work.

You should be able to convert to date from this format fine. 

See example code below. If this works for you, accept @mahoneypat's answer as this is just supplemental to his.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMjAEIiUdJaVYHTjfCI1vDORDmIZGYHEE3xiNb6IUGwsA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FirstPODDate = _t, LastPODDate = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source,"",null,Replacer.ReplaceValue,{"LastPODDate", "FirstPODDate"}),
    #"Added Custom" = Table.AddColumn(#"Replaced Value", "Custom", each [FirstPODDate]??[LastPODDate]),
    #"Changed Type" = Table.TransformColumnTypes(#"Added Custom",{{"Custom", type date}})
in
    #"Changed Type"
Have I solved your problem?
Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;).
chrome-9xf-Zagzel-B

If you found this post helpful, please give Kudos.
It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen.
If you find my signature vaguely amusing, please give Kudos.
KIfp67uy-Sr
Proud to be a Super User!PBI-Super-User-Rank-30x30-1x

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