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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kartiklal18
Helper II
Helper II

Calculate no. of working days that have passed in the year so far

Hi, 

 

I have a calendar table where I'm using a calculated column to calculate the no. of working days in each month this year. 

 

Based on this column and the current date, I want to calculate the no. of working days that have passed year to date. Please see screenshot below for no. of working days by month. Essentially, I want this formula to return 21 for January, 20 for Feb and 19 for March (since based on today's date we have 2 more working days left in March) and the total to be 60. I have tried a few different formulas but can't seem to get the desired result, mainly the total is almost always incorrect. 

 

Thank you for any suggestions!

 

Working Days Year.PNG

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

YTD Sales = CALCULATE(SUM('Date'[Working Day]),DATESYTD(('Date'[Date]),"12/31"))

 

But for that, you need have a filter of the date on the page

or try like

YTD Sales = CALCULATE(SUM('Date'[Working Day]),DATESYTD(('Date'[Date]),"12/31"),'Date'[Date]<=today())

View solution in original post

4 REPLIES 4
v-kelly-msft
Community Support
Community Support

Hi @kartiklal18

Take year 2020 for example:

1.Create a calendar table using below dax expression:

 

 table = CALENDAR(DATE(2020,1,1),DATE(2020,12,31)) 

 

2.Then create 3 calculated columns:

 Month = FORMAT('table'[Date],"MMMM") 

 

weekday = WEEKDAY('table'[Date],2)

 

Working day = IF('table'[weekday]<>6&&'table'[weekday]<>7,1,0)

 

3.Fianlly create a measure as below:

Measure = IF(MONTH(MAX('table'[Date]))=MONTH(TODAY()),CALCULATE(SUM('table'[Working day]),'table'[Date]<=TODAY()),SUM('table'[Working day]))

 

And you will see:

Annotation 2020-03-31 112312.png

 

 

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

 

Hi all,

 

Thanks for all your suggestions. @amitchandak , your solution works and its what I needed. 

 

 

Greg_Deckler
Super User
Super User

First, Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

If you have a Calendar, then you should be able to create a column like:

Working Day = IF(WEEKDAY([Date],2)<6,1,0)

 

You should then just be able to SUM the Working Day column to get the number of working days and the totals should be correct.

 

If you are using some kind of measure, you may have a measure totals issue. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
amitchandak
Super User
Super User

YTD Sales = CALCULATE(SUM('Date'[Working Day]),DATESYTD(('Date'[Date]),"12/31"))

 

But for that, you need have a filter of the date on the page

or try like

YTD Sales = CALCULATE(SUM('Date'[Working Day]),DATESYTD(('Date'[Date]),"12/31"),'Date'[Date]<=today())

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.