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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
niklasgrundel
Regular Visitor

Need help to measure days between to dates in a column, with a twist

Hi, 

 

I need help to calculate days between column A and column B, the result should be presented in column C. I´ve managed to calculate days between A and B if they both contain dates. The twist is that I wan´t to use present day and calculate with order day if delivery date is missing. So column C should always present data.

I´m not really sure if this can be accomplished using Dax...

 

I´ve tried this code in a Power Query but it won´t work:

if ['Delivery date']=""

then (DateTime.Date-['Order date'])

else

(['Delivery Date']-[#"Order date"])

 

pbi_measure_days.jpg

 

Thanks in advance!

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @niklasgrundel 

In Power query you can create a custom column

= if [Delivery Date]="" or [Delivery Date]=null 
then Date.From(DateTime.LocalNow())-[Order date]
else [Delivery Date]-[Order date]

 

In DaX you can create a calculated column:

Column = 
IF(ISBLANK([Delivery Date]), DATEDIFF([Order Date], TODAY(), DAY), DATEDIFF([Order Date], [Delivery Date], DAY) )

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

5 REPLIES 5
az38
Community Champion
Community Champion

Hi @niklasgrundel 

In Power query you can create a custom column

= if [Delivery Date]="" or [Delivery Date]=null 
then Date.From(DateTime.LocalNow())-[Order date]
else [Delivery Date]-[Order date]

 

In DaX you can create a calculated column:

Column = 
IF(ISBLANK([Delivery Date]), DATEDIFF([Order Date], TODAY(), DAY), DATEDIFF([Order Date], [Delivery Date], DAY) )

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Thanks @az38 for quick reply!

 

I manged to get you DaX-code to work as you can see below, the Power query won´t show and present days where the delivery date column is missing data, can it be a problem with Date.From(DateTime.LocalNow())?

 

DaxCode.jpg

 

 

 

 

 

PQcode.jpg

Hi @niklasgrundel 

try null without quotas in Power query, just = null

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

 


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

- To quote or note to quote, that´s the question!? 😉

 

When I removed the quotation of null your Power Query script worked aswell.

 

Thanks for your patience and help!

There is no question, if I see null 🙂

Good luck!

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.