Forum Discussion
WORKDAY formula in Power BI
- Anonymous9 years ago
Firstly, import your Federal Holiday sheet and data table to Power BI Desktop.
Secondly, create a calendar table using calendar() function, create relationship between data table and calendar table using date field, and create relationship between Federal Holiday table and calendar table using date field, here is an example for you.
Thirdly, create the following calculated columns in the calendar table.
WeekDay = WEEKDAY('Calendar'[Date])
Holiday = RELATED('Federal Holiday'[Holiday])
If work day = IF(OR('Calendar'[WeekDay]=1,'Calendar'[WeekDay]=7),0,IF(ISBLANK('Calendar'[Holiday]),1,0))
Rank = RANKX(FILTER('Calendar','Calendar'[If work day]=1),'Calendar'[Date],,ASC)
Add 3 businss days = LOOKUPVALUE('Calendar'[Date],'Calendar'[If work day],1,'Calendar'[Rank],'Calendar'[Rank]+3)At last, create a calculated column using the following DAX in your data table.
Column = RELATED('Calendar'[Add 3 businss days])
Regards,
Firstly, import your Federal Holiday sheet and data table to Power BI Desktop.
Secondly, create a calendar table using calendar() function, create relationship between data table and calendar table using date field, and create relationship between Federal Holiday table and calendar table using date field, here is an example for you.
Thirdly, create the following calculated columns in the calendar table.
WeekDay = WEEKDAY('Calendar'[Date])
Holiday = RELATED('Federal Holiday'[Holiday])
If work day = IF(OR('Calendar'[WeekDay]=1,'Calendar'[WeekDay]=7),0,IF(ISBLANK('Calendar'[Holiday]),1,0))
Rank = RANKX(FILTER('Calendar','Calendar'[If work day]=1),'Calendar'[Date],,ASC)
Add 3 businss days = LOOKUPVALUE('Calendar'[Date],'Calendar'[If work day],1,'Calendar'[Rank],'Calendar'[Rank]+3)
At last, create a calculated column using the following DAX in your data table.
Column = RELATED('Calendar'[Add 3 businss days])
Regards,
- Eagles838 years agoNew Member
I get an error at Step 3 saying Expression.Error: The name 'WEEKDAY' wasn't recognized. Make sure it's spelled correctly.
Is WeekDay a dax formula or do I need to add a WeekDay table?
- Eagles838 years agoNew Member
This was very helpful. Can you please clarify which 'Date' in your response represents my "DateX" in my question? I'm not sure if my DateX is the Date if the Fact Table for the Date in the Calendar table.
- Anonymous7 years agoNot applicable
It's possible to calculate workdays without a Date table with the following Measure or Calculated Column in DAX:
Workdays Calculated =//the work days don't consider Saturdays and Sundays//calculate the number of days between the dates, and adds 1VAR numDays = DATEDIFF([Start Date], [End Date], DAY) + 1//verifies the week numbers of each dateVAR weekNumStart = WEEKNUM([Start Date])VAR weekNumEnd = WEEKNUM([End Date])//calculates the number of weekends existing between datesVAR numWeekends = IF(weekNumStart <= weekNumEnd, //weeks in same yearweekNumEnd - weekNumStart, //the difference is the number of weekendsweekNumEnd - weekNumStart + 52 //if different years, adds the number of weeks in one year)RETURNnumDays - (numWeekends * 2) //calculates the number of days (*2 to remove Saturday and Sunday for each weekend)