Forum Discussion
NETWORKDAYS type function in PowerBI
I have a table (vw_WorkCenterUtilization) and a date column (Work_Date) that I need to calculate the oldest and newest date in the data, and the number of work days within it. I'm using the FIRSTDATE and LASTDATE functions in seperate Measures to draw this number, but I do not know how to only include the number of work days in the range. My current code to calculate the days different is as follows
Days = DATEDIFF([OldestDate],[NewestDate],DAY)
How would I go about getting this info if there is no NETWORKDAYS function like their is in Excel? Attached is my current output in screenshot as well. I beleive the number I'm looking for should be 261 days, not 365.
Thank you!
- Anonymous9 years ago
Hi kyleldi,
Firstly, create a calendar table in Power BI Desktop following the guide in this blog. Then create a column in the calendar table using the Dax below.is work day = SWITCH(WEEKDAY([Date]),1,0,7,0,1)
Secondly, create a measure using the following DAX and create a card visual.
Days= CALCULATE(SUM('Date'[is work day]), DATESBETWEEN('Date'[Date], [OldestDate], [NewestDate] ))Thanks,
Lydia Zhang
17 Replies
- AnonymousNot applicable
Hi kyleldi,
Firstly, create a calendar table in Power BI Desktop following the guide in this blog. Then create a column in the calendar table using the Dax below.is work day = SWITCH(WEEKDAY([Date]),1,0,7,0,1)
Secondly, create a measure using the following DAX and create a card visual.
Days= CALCULATE(SUM('Date'[is work day]), DATESBETWEEN('Date'[Date], [OldestDate], [NewestDate] ))Thanks,
Lydia Zhang- sureshdam18Frequent Visitor
Hi,
I want to calculate Network days between Created Date to Till Date, My date filed looks like,
How can we Calculate, If i am tring the above Dax calculation it is geving the error. calculation is,
is work day = SWITCH(WEEKDAY([Created Date]),1,0,7,0,1)
NetworkDays = CALCULATE(SUM([is work day]),
DATESBETWEEN([Created Date].[Date],Sheet1[Created Date],TODAY()
))Open Request = IF(AND('Fusion dashboard report'[Completion Status]="Open", [Status]="MDM Ops Review - Undelete"),'Fusion dashboard report'[Network days], -1)
While i am using this Calculation it showing the below error.
A circular dependency was detected: Fusion dashboard report[Network days], Fusion dashboard report[Open - FLS / Requestor in Days], Fusion dashboard report[Network days].
please help me on this.
Thanks in Advance.
- AnonymousNot applicable
This looks fine, how to get number of hours as well, so times tickets open on same day and closed on same day. the mentioned formula get 1 day for this as well. but wanted to claculate hours in this scenario.
Thanks,
Thimma - JoMannRegular Visitor
Hi,
When I try to create the measure (last step of your instructions) i get an error message: "A single value for column 'Total Revenue' in table 'SalesData' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."
Ho wdo i resolve that? Also are we meant to create a relationship with the Date/Calendar Table and the table containing our start and end dates?
- AnonymousNot applicable
I found an easier solution one column and one measure, but it could be a column if you don't need it to be dynamic.
Column
Weekday = WEEKDAY(WEEKDAY(MyTable[MyDate],2)) Note: the 2 at the end makes it Monday 1 - Sunday 7
Measure
NetWorkDays = COUNTAX(FILTER(MyTable,AND(MyTable[MyDate]>= MyTable[MyStartDate], MyTable[Weekday]<6)), MyTable[MyDate]) - COUNTAX(FILTER(MyTable,AND(MyTable[MyDate]> MyTable[MyEndDate], MyTable[Weekday]<6)), MyTable[MyDate]) Note: this is counting all weekdays after the start date and then subtracting all weekdays after the end date.
If you needed to deal with holidays it would be pretty simple as well, just add a new column to indicate Holidays or even a seperate holiday date table and you can use that to filter out the holidays from your count.
- juliarusmanicaNew Member
I am trying to computer network days between two dates.
I tried:
Days = COUNTROWS(FILTER(CALENDAR(DATE(ReceivingLog[Receipt Date].[Year],ReceivingLog[Receipt Date].[Month],ReceivingLog[Receipt Date].[Day]),date(ReceivingLog[Inspection Date].[Year],ReceivingLog[Inspection Date].[Month],ReceivingLog[Inspection Date].[Day])), WEEKDAY([Date])<>1 && WEEKDAY([Date])<>7))and am getting error:Cannot convert value 'January' of type Text to type Integer.What can I do?TY.- AnonymousNot applicable
The issue is the Month formula requires an integer value it can't convert the text based month i.e. January. You can try a new column that converts the months to a value something like IF(MyMonth - "Januaury", 1, IF(MyMonth = "Februaury", 2 ... etc.
- juliarusmanicaNew Member
Do I add that column to my table [ReceivingLog]? or do I click Add data and create a table with one column [MonthNumber}?
- Ashish_MathurSuper User
Hi,
Does this work?
Days = COUNTROWS(FILTER(CALENDAR(min(ReceivingLog[Receipt Date]),max(ReceivingLog[Inspection Date])),WEEKDAY([Date],2)<=5))
- QooTFrequent Visitor
Maybe its old topic but easises solution is to create a custom function lik this:
(StartDate as date, EndDate as date) as number =>
let
DateList = List.Dates(StartDate, Number.FromText(EndDate-StartDate), #duration(1,0,0,0)),
RemoveWeekdns = List.Select(DateList, each Date.DayOfWeek(_, Day.Monday)<5),
CountDays = List.Count(RemoveWeekdns)
in
CountDays
And then just invoke it whenever needed.- AlexanderPrimeSolution Supplier
They also just added NETWORKDAYS in DAX this month.
- Stephen_SinkFrequent Visitor
Do I have to update my version of desktop to get this? im running 2.105