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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
RRaj_293
Helper III
Helper III

Dax Help for No of working days

Hi , 

I am trying to create a dax for calculating the number of days between Despatch date and target despatch date. Expected results as below. The calcualtion should also take into consideration different warehouses working days and public holidays into consideration. Weekends and public holidays to be excluded. 

Below is the data model -

RRaj_293_0-1693741452430.png

Date table - is a pure calendar table .

Warheouse table - Dimension table which has warheouse details.

Warehouse calendare table - This table holds the ,calendar date information for every warehouse. It has a field called "is Working Day" = Treu/False , which indicates where its a working day/not for every warehouse code for all years.

Fact table - holds all the dates and other info. Warehouse date calendar is not direclty connected to Fact table . It is connected via warehouse table

 

The dax(below) I wrote doesnt seem to work as the "Is working Day" filter is not getting applied although used in filter of the dax.Not sure if its b'coz there is no direct relation between fact and warehouse calendar.

 

Not excluding weekends-
NoofDays_line = var startdate = IF(SELECTEDVALUE('Fact'[Despatch Date]) = BLANK() , BLANK(),SELECTEDVALUE('Fact'[Despatch Date]))
var enddate = IF(SELECTEDVALUE('Fact'[Target Despatch Date])= BLANK() , BLANK(),SELECTEDVALUE('Fact'[Target Despatch Date]))
VAR WarehouseCode = SELECTEDVALUE('Fact'[Warehouse_Code])
Return
CALCULATE(DATEDIFF(startdate,enddate,DAY),
FILTER('Warehouse','Warehouse'[Warehouse Code] = WarehouseCode),FILTER(ALL('Warehouse Date Calendar'),'Warehouse Date Calendar'[Is Working Day] = TRUE()))

Expected result-

Note- Need both + and - sceanrios where despatch date could be On, before or After target despatch date.

15-Sep-2317-Sep-23Melb216,17 hence 2 days.
21-Sep-2318-Sep-23Melb-3It shld be a negative number as despatch date is after the target depstach date.
22-Sep-2328-Sep-23NSW2Assume 27th Sep was a public holiday only in NSW hence 2 days excluding weekends and Public holidays
21-Sep-2321-sEP-23NSW0as both dates are same.
22-Sep-2328-Sep-23Melb4No public holidays , only weekends excluded.
     
     
3 REPLIES 3
Anonymous
Not applicable

Hi @RRaj_293 ,

Please have a try.

NoofDays_line = 
VAR StartDate = SELECTEDVALUE ( 'Fact'[Despatch Date] )
VAR EndDate = SELECTEDVALUE ( 'Fact'[Target Despatch Date] )
VAR WarehouseCode = SELECTEDVALUE ( 'Fact'[Warehouse_Code] )
RETURN
CALCULATE (
    COUNTROWS ( 'Warehouse Date Calendar' ),
    USERELATIONSHIP ( 'Fact'[Warehouse_Code], 'Warehouse Date Calendar'[Warehouse Code] ),
    'Warehouse Date Calendar'[Is Working Day] = TRUE (),
    DATESBETWEEN ( 'Warehouse Date Calendar'[Date], StartDate, EndDate )
)

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you so much for responding. Since there was no response for couple of days after posting , I resolved it in SQL after really trying hard for days .

However on the Dax (from my learning perspective), doing a count of rows for dates between start and end date does not give me the negative numbers where despatch date is greater than target despatch date. which is why I used datesdiff . so I'm pretty sure this dax wont fully serve the purpose as I did the same before arrving with Datesdiff. For numbers which have to show up as negative it will return 0 and in business terms it would mean orders were despatched on the same day as target day which is incorrect. 

 

Appreciate your time and effort in responding to my query. Thanks a lot.

RRaj_293
Helper III
Helper III

Sorry table missing column names - here you go.

 

despatch dateTarget Despatch dateWarehouseNo.Of working days
15-Sep-2317-Sep-23Melb216,17 hence 2 days.
21-Sep-2318-Sep-23Melb-3It shld be a negative number as despatch date is after the target depstach date.
22-Sep-2328-Sep-23NSW2Assume 27th Sep was a public holiday only in NSW hence 2 days excluding weekends and Public holidays
22-Sep-2328-Sep-23Melb4No public holidays , only weekends excluded.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.