cancel
Showing results for
Did you mean:
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"])

1 ACCEPTED SOLUTION

Accepted Solutions
Super User II

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

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

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

5 REPLIES 5
Super User II

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

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

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

Regular Visitor

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

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())?

Super User II

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

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

Regular Visitor

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

- 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!

Super User II

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

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

Announcements

#### New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

#### ‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

#### Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

#### Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

#### Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors