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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
markefrody
Post Patron
Post Patron

DAX DATEDIFF Working Days and Others

Hi, 

 

I am trying to get the date difference between Load Date and Plan Date but I need to exclude Saturdays and Sundays. Also if the Plan Date is blank, I need today's date + 1 day to replace the blank Plan Date and from there compute the date difference.

 

Can this be done in DAX? Appreciate if you can help me to create DAX formula as per my above requirements. Thanks!

Capture Date.PNG

 

Best regards,

Mark Visda

5 REPLIES 5
v-cherch-msft
Employee
Employee

Hi @markefrody 

 

You may create a calendar table and use below measure.Attached the sample file for reference.

Measure = 
CALCULATE (
    COUNT ( 'Calendar'[Date] ),
    FILTER (
        GENERATE ( Table1, FILTER ( 'Calendar', 'Calendar'[ISWeekum] = 0 ) ),
        Table1[Load Date] < 'Calendar'[Date]
            && Table1[Plan Date2] >= 'Calendar'[Date]
    )
)

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-cherch-msft (Cherie),

 

Thank you for sending your suggestion. Unfortunately I cannot creat a calendar table since I am using a Direct Query for storage method. Is there any other way to do this without adding a calendar table?

 

Best regards,

Mark V

Hi @markefrody 

 

Try below measure:

Measure 2 = var _Calendar=ADDCOLUMNS(CALENDAR(DATE(2019,1,1),DATE(2019,3,1)),"ISWeekum",IF(WEEKDAY([Date],1)>=6,1,0))
return CALCULATE (
    COUNTROWS(
    FILTER (
        GENERATE (Table1,FILTER(_Calendar,[ISWeekum]=0) ),
        Table1[Load Date] < [Date]
            && Table1[Plan Date2] >= [Date]
    )
)
)

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

Have a look at this:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Net-Work-Days/m-p/367362

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler. Thank you for sending your suggestion. I have tried to do the measure:

Capture 1.PNG

 

But I am getting this error:

 

Capture 2.PNG

Is it because I have blank data in some of my dates? 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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