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
jgarcin8
Frequent Visitor

Get the difference between 2 dates excluding weekends. Storage Mode: Direct Query

Hello,

 

Im trying to calculate the difference in days between 2 dates: 'SubmittedDate' and 'LastModifiedDate' excluding weekends.

jgarcin8_0-1643243363124.png

 

I have 2 sql tables here:

*Table 'Query1' in which I have the fields "'SubmittedDate' and 'LastModifiedDate'

jgarcin8_1-1643243463685.png

*Table 'Query2'  which is a Calendar table and I have a column ('IsWeekday') to identify Saturdays and Sundays.

jgarcin8_2-1643243564802.png

jgarcin8_3-1643243637459.png

Saturdays and Sundays ='False'

Monday to Friday='True'

 

How Can I combine these 2 tables to get the diff in days?  My tables are in storage mode: DirectQuery so Im having problems with "calculate" or "count" functions.

 

Really appreciate you help @amitchandak 

Thank you so much! 

1 ACCEPTED SOLUTION
sevenhills
Super User
Super User

Try this and see if it works (as column)

 

Working Days Calc = 
DateDiff ('Query1'[SubmittedDate], 'Query1'[LastModifiedDate], Day) -
(
   CALCULATE (
          countrows('Query2'),
          'Query2'[IsWeekDay] = FALSE(),
          DatesBetween('Query2'[Date], 'Query1'[SubmittedDate], 'Query1'[LastModifiedDate] - 1)
   )
)

 

 

Other way (simplified)

 

Working Days Calc = 
   CALCULATE (
          COUNTROWS('Query2'),
          DatesBetween('Query2'[Date], 'Query1'[SubmittedDate], 'Query1'[LastModifiedDate] - 1), 
          'Query2'[IsWeekDay] = FALSE(),
          All('Query2')
  )

 

 

The only thing you may need to consider based on your requirement is to do "-1", to include the end day or not, depends on your requirements

View solution in original post

8 REPLIES 8
jgarcin8
Frequent Visitor

Hi

I changed the Dashboard to "Import mode" and the formula works! 😁 Thank you so much!

sevenhills
Super User
Super User

Try this and see if it works (as column)

 

Working Days Calc = 
DateDiff ('Query1'[SubmittedDate], 'Query1'[LastModifiedDate], Day) -
(
   CALCULATE (
          countrows('Query2'),
          'Query2'[IsWeekDay] = FALSE(),
          DatesBetween('Query2'[Date], 'Query1'[SubmittedDate], 'Query1'[LastModifiedDate] - 1)
   )
)

 

 

Other way (simplified)

 

Working Days Calc = 
   CALCULATE (
          COUNTROWS('Query2'),
          DatesBetween('Query2'[Date], 'Query1'[SubmittedDate], 'Query1'[LastModifiedDate] - 1), 
          'Query2'[IsWeekDay] = FALSE(),
          All('Query2')
  )

 

 

The only thing you may need to consider based on your requirement is to do "-1", to include the end day or not, depends on your requirements

Hi

Thank you for the quick reply. Im having the next issue:

jgarcin8_1-1643254431670.png

 

The same issue with both formulas 😞 

a) Did you try to do as New Column? 

 

b) 'Query2'[IsWeekDay] = "False" ... change this.

         it is saying the data types are wrong

 

If this does not work, share the data types

Hi,

 

Yes, I tried as "New column".

 

I changed to  'Query2'[IsWeekDay] = "False" ... and seems for that sentence works.

 

But now appears this:

jgarcin8_0-1643255128016.png

 

Can you share the .pbix file ... ? (remove the sensitive information)

 

Note: You can create with mockup data and then share please, sorry tough to diagnose without pbix file

Hi

I changed the Dashboard to "Import mode" and the formula works! 

 

 Thank you so much!

Glad it worked in the end!

 

... sorry somtimes if we dont have code and error reproduce, it is tough ... 

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.

Top Solution Authors
Top Kudoed Authors