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
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.
mahoneypat
Employee
Employee

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!!!
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...

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!!!
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...

@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!!!
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...

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.