Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
I need to calculate the number of days between two date fields EXCLUDING weekends. I have tried a bunch of times but can't seem to get it correct. It is a simple single data table with an "Order Date" field and "Invoice Date" field. I just want to know the number of work days between them. I know I can subtract to get total days but I need to take out the weekend days for it to be accurate for my purposes.
I do not want to use or import a separate Calendar Table to do this, since I have both required date fields in the original data table. Excel can do this quite easily but Power BI should have a simpler way to do it. Am I missing something?
i.e. An Order Date = 12/6/17 & Invoice Date = 1/9/2018 - is 34 days, but is really "24" week days.....
Solved! Go to Solution.
Hi @ianneg77,
Assuming you have a calendar table, then you could create a calculated column with the formula provided by @robenanderson to calculated the workdays.
workdayflag = if( weekday( 'DateTable'[date]) = 1,0, if( weekday( 'DateTable'[date])=7,0,1) )
Then you could create the networkdays column by the formula below.
networkdays = CALCULATE ( SUM ( 'DateTable'[workdayflag] ), DATESBETWEEN ( 'DateTable'[Date], 'Table1'[orderdate], 'Table1'[invoice date] ) ) - 1
Hope this can help you!
Best Regards,
Cherry
could you create a table (or add to a calendar table) a flag if it is a working day? for example, If M-F then 1, otherwise Sat and Sun would be 0? Then, do a calculate with the sum set to that workday flag, and a filter to the date is greater than or equal to the Order date and another filter that is less than or equal to the invoice date?
I do have a calendar file I can add to. But I am not great with DAX yet been using Power BI a few months, so when it comes to filtering I may be in the weeds some.
Hi @ianneg77,
Assuming you have a calendar table, then you could create a calculated column with the formula provided by @robenanderson to calculated the workdays.
workdayflag = if( weekday( 'DateTable'[date]) = 1,0, if( weekday( 'DateTable'[date])=7,0,1) )
Then you could create the networkdays column by the formula below.
networkdays = CALCULATE ( SUM ( 'DateTable'[workdayflag] ), DATESBETWEEN ( 'DateTable'[Date], 'Table1'[orderdate], 'Table1'[invoice date] ) ) - 1
Hope this can help you!
Best Regards,
Cherry
the article I linked shows how to do multiple filters, and I believe it would be something like this. I apologize in advance with my formatting. I'm not a good code formatter.
First, here's formula to create workday flag (1 or 0) that you can then sum in next formula. weekday = 1 is Sunday, 7 is Saturday FYI.
workdayflag = if( weekday( calendartable[date]) = 1,0, if( weekday( calendartable[date])=7,0,1) )
then, based on the article I linked, something like this should work
DaysBetween MEASURE = CALCULATE ( SUM ( calendar[workdayflag] ), FILTER ( INFOTABLE, INFOTABLE[ORDER DATE] >= calendar[DATE] && INFOTABLE[INVOICE DATE] <= calendar[DATE] ) )
These should at least get you close to what you're looking for. Be sure to create measure of this. You may need to create another date column or something that can have a relationship connected to it, but I could be wrong in that. Like you, I haven't been working with Power BI for more than a few months. With that said, someone more experienced may have something better to add to this, or something easier.
User | Count |
---|---|
140 | |
113 | |
104 | |
77 | |
65 |
User | Count |
---|---|
136 | |
118 | |
101 | |
71 | |
61 |