cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
carlosagarcia
Helper I
Helper I

Count working days for a month to get an average

Hello Everyone.

 

My intent is to calculate the number of working days for each month and display the number for the current month to get an average, For Example.

I created a report that tracks the number of lines processed, I would like to automatically devide the number of lines processed with the number of working days for the current month . I can do this manually  = Countoflines / 22 but I would have to change the number of working days each month. Will it be possible to have this automated so that when we switch to the next month it changes automatically?

1 ACCEPTED SOLUTION

Hi @carlosagarcia,

Here is a calculated column expression that can be used to calculate the current month workdays(except weekend) based on date value, you can try it if helps:

CMonthWorkDay=
VAR currDate ='Date'[Date] 
RETURN
    COUNTROWS (
        FILTER (
            GENERATESERIES (
                DATE ( YEAR ( currDate ), MONTH ( currDate ), 1 ),
                DATE ( YEAR ( currDate ), MONTH ( currDate ) + 1, 1 ) - 1
            ),
            WEEKDAY ( [Date], 2 ) <= 5
        )
 )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

11 REPLIES 11
v-shex-msft
Community Support
Community Support

Hi @carlosagarcia,

if you can please share some dummy data that keep the raw data structure and expected results. It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hello @v-shex-msft  What I want to do it is to count the working days for the current month.

For example  in this case July 2021 has 22 working days, I want to be able to see the working days displated on a card or a table so I can use it to get an average of lines processed.

 

This seems to be a good method but I am unable to recreate the MonthYear table.

 

carlosagarcia_0-1627563917467.png

 

 

https://stackoverflow.com/questions/59242331/calculate-number-of-working-days-based-on-a-month-and-y...

 

 

Hi @carlosagarcia,

Here is a calculated column expression that can be used to calculate the current month workdays(except weekend) based on date value, you can try it if helps:

CMonthWorkDay=
VAR currDate ='Date'[Date] 
RETURN
    COUNTROWS (
        FILTER (
            GENERATESERIES (
                DATE ( YEAR ( currDate ), MONTH ( currDate ), 1 ),
                DATE ( YEAR ( currDate ), MONTH ( currDate ) + 1, 1 ) - 1
            ),
            WEEKDAY ( [Date], 2 ) <= 5
        )
 )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

mahoneypat
Super User
Super User

Do you have a Date table with a column to indicate working days?  If so, you can use an expression like this

 

Count per WD =
VAR countoflines = [Your Count Measure]
VAR WD =
    CALCULATE ( COUNTROWS ( 'Date' ), 'Date'[IsWorkingDay] = "Y" )
RETURN
    DIVIDE ( countoflinesWD )

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hello Ma,

 

I do not have a date table, I treid different methods over the weekend with various posts and I could not find one that will give the total amount of days, it was always decending one by one.

 

This is as far as I got.

 

Date = CALENDAR (DATE(2021,1,1), DATE(2022,12,31))
 
WorkingDays =
VAR Year = YEAR( [Date] )
VAR Month = MONTH( [Date] )
VAR DatesInMonth = GENERATESERIES( [Date], DATE( Year, Month + 1, 1 ) - 1, 1 )
RETURN SUMX(
DatesInMonth,
IF( WEEKDAY( [Value] ) IN { 1, 7 }, 0, 1 )
)
 

 

@carlosagarcia 

WorkingDaysCurrentMonth = 
  VAR __Calendar = 
    ADDCOLUMNS(
      CALENDAR(DATE(2021,1,1),DATE(2021,12,31))
      "IsWorkDay", IF(WEEKDAY([Date],2),1,0)
    )
  VAR __Today = TODAY()
  VAR __Start = DATE(YEAR(__Today),MONTH(__Today),1)
  VAR __End = EOMONTH(__Today,0)
RETURN
  COUNTROWS(FILTER(__Calendar,[IsWorkDay]=1 && [Date] >=__Start && [Date]<=__End))

@ me in replies or I'll lose your thread!!!
Check out my External Tool for Power BI Desktop!
Microsoft Hates Greg's Quick Measures
Check out my latest book!

Hello @Greg_Deckler   Would you still be able to help me out?

@carlosagarcia Sorry, syntax error, should be:

"IsWorkDay", IF(WEEKDAY([Date],2)<6,1,0)

@ me in replies or I'll lose your thread!!!
Check out my External Tool for Power BI Desktop!
Microsoft Hates Greg's Quick Measures
Check out my latest book!

@Greg_Deckler  when you reffer to IsWorkDay what are you refering too?

The Dax query still does not recognize that name.  I really apreciate the help. 

 

carlosagarcia_0-1627394219310.png

 

 

 

Hello @Greg_Deckler , You lost me on the IsworkDay. I have attached a screen shot.

 

carlosagarcia_1-1627303268513.png

 

 

 

 

Greg_Deckler
Super User
Super User

@carlosagarcia So, generally, you can create a "IsWorkingDay" column in your calendar table using something like:

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


@ me in replies or I'll lose your thread!!!
Check out my External Tool for Power BI Desktop!
Microsoft Hates Greg's Quick Measures
Check out my latest book!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Power BI October Update 2021.jpg

Power BI Release

Click here to read more about the October 2021 Release!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Teds Dev Camp Oct. 2021 768x460.jpg

Power BI Dev Camp - October 28th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!