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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
DataScope06
Helper I
Helper I

Custom column - Select date from one column, or other date columns if null

My dataset has 3 different column dates: ORDER_DATETIME, ACTUAL_SHIPMENT_DATE, PROMISE DATE. I have a preferred hierarchy for selecting dates for a custom date column. If one of the date fields is null, then the next date field in the hierarchy should be used.

 

I have the SQL code but don't know the proper dax function. SQL is below

 

 CASE WHEN

ACTUAL_SHIPMENT_DATE is null then PROMISE_DATE
              WHEN PROMISE_DATE is null then ORDER_DATETIME
              else ACTUAL_SHIPMENT_DATE

END

 

The table looks like this

 

ACTUAL_SHIPMENT_DATEPROMISE_DATEORDER_DATETIME
1/1/20201/2/202012/31/2019
 3/1/2020 
 2/1/20212/2/2021
  4/1/2021

 

I would like a date column that shows this:

Date
1/1/2020
3/1/2020
2/1/2021
4/1/2021
1 ACCEPTED SOLUTION
vojtechsima
Super User
Super User

Hello, @DataScope06,
this should work:

Date = 
var ActualShipment = 'Table'[ACTUAL_SHIPMENT_DATE]
var Promise = 'Table'[PROMISE_DATE]
var Order_ = 'Table'[ORDER_DATETIME]

var check = 
SWITCH(TRUE(),
    ISBLANK(ActualShipment), IF(ISBLANK(Promise), Order_, Promise),
    ActualShipment
 )

return check

vojtechsima_0-1666987982882.png

 

 

View solution in original post

2 REPLIES 2
vojtechsima
Super User
Super User

Hello, @DataScope06,
this should work:

Date = 
var ActualShipment = 'Table'[ACTUAL_SHIPMENT_DATE]
var Promise = 'Table'[PROMISE_DATE]
var Order_ = 'Table'[ORDER_DATETIME]

var check = 
SWITCH(TRUE(),
    ISBLANK(ActualShipment), IF(ISBLANK(Promise), Order_, Promise),
    ActualShipment
 )

return check

vojtechsima_0-1666987982882.png

 

 

I think your answer works, I will mark that as the solution, @vojtechsima.

 

Before you submitted the solution I did figure out how to make a custom column in Power BI, then I used this formula (copied from power query):

 

if [ACTUAL_SHIPMENT_DATE] != null then [ACTUAL_SHIPMENT_DATE]

else if [ACTUAL_SHIPMENT_DATE] = null then [PROMISE_DATE]

else if [PROMISE_DATE] = null then [ORDER_DATETIME]

else [ACTUAL_SHIPMENT_DATE]

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.