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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
EmilyM2019
Helper II
Helper II

DAX for date column

Hi all,

 

I am stuck with a DAX if someone can help me.

 

I have a table with 2 date columns, Column A and Column B. 

 

I want a new column (Column C) that will look and see if there is a value in Column A, if it is blank it picks up the value from Column B. If Column A isn't blank then it populates Column C with that value. As per the table below.

 

TIA, Emily.

 

Column AColumn BColumn C
 03/02/202003/02/2020
02/01/202021/01/202002/01/2020
13/01/202001/02/202013/01/2020
19/01/202003/02/202019/01/2020
24/12/201931/12/201924/12/2019
 15/12/201915/12/2019
 30/12/202030/12/2020
1 ACCEPTED SOLUTION

I'm sorry I forget to add the null cases too. Try this:

if [ColumnA] = "" or [ColumnA] = null then [ColumnB] else [ColumnA]

Regards, 


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

View solution in original post

7 REPLIES 7
ibarrau
Super User
Super User

Hi there. You should consider do this in Power Query over the query editor. If you want DAX use the first answer, if you want power query try adding a custom column like this:

 

if [ColumnA] = "" then [ColumnB] else [ColumnA]

 

Just ask if columnA is blank and you can get the true false with the columns.

 

Hope this helps,

Regards


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Hi,

 

Thanks for coming back to me. I'm now trying to do this in Power query but it hasn't worked. Using the add custom column option I have done:

 

= Table.AddColumn(#"Renamed Columns2", "Custom", each if[Column A]=""then[Column B]else[Column A])

 

and it isn't working. The only value that is returning in the new custom column is the value of column A.

 

Any ideas? 

I'm sorry I forget to add the null cases too. Try this:

if [ColumnA] = "" or [ColumnA] = null then [ColumnB] else [ColumnA]

Regards, 


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Thank you, this has worked, hurrah.

 

Just to build on this how would I do:

 

If column A and column B are blank then return todays date?

Well it should be similar

 

if [ColumnA] = "" or [ColumnA] = null then
if [ColumnB] = "" or [ColumnB] = null then 
DateTime.LocalNow() 
else [ColumnB] else [ColumnA]

 

You can continue adding if statements in the "then" or "else" in case you need them.

Regards,


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Thanks for your help.

MariusT
Helper II
Helper II

Hi @EmilyM2019 ,

 

Try the following:

 

Date = if(isblank('Table'[ColumnA]);'Table'[ColumnB];'Table'[ColumnA])

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.