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
Mohivaj
New Member

Need help to calculate average count of the column based on week type column

This is my example table which already has the weektype. Employees are in shift on different week type. I want to calulate the average of employees baesd on weektype (weekend/weekday)

Employeeweektypedateteam
AAAweekendSaturdayA
AAAweekdayMondayA
BBBweekdayTuesdayB
AAAweekdayWednesdayA
CCCweekdayThursdayC
2 ACCEPTED SOLUTIONS

@Mohivaj I still don't know if I understand what you are asking for, an average over what? But, maybe you are looking for something like this:

Average Weekday =
  VAR __Table = SUMMARIZE( FILTER('Table', [weektype] = "weekday"), [date], "__Count", COUNTROWS('Table') )
  VAR __Result = AVERAGEX( __Table, [__Count])
RETURN
  __Result

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

View solution in original post

v-nuoc-msft
Community Support
Community Support

Hi @Mohivaj 

 

@Greg_Deckler  Thank you for sharing !

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"Table"

vnuocmsft_0-1708416304494.png

 

Create a measure. Calculate the average number of employees working on weekdays and weekends for different teams.

 

Average Employee = 
var _week = 
    CALCULATE(
        COUNTROWS('Table'), 
        FILTER(
            ALL('Table'), 
            'Table'[weektype] = MAX('Table'[weektype]) 
            && 
            'Table'[team] = MAX('Table'[team])
        )
    )
var _total = 
    CALCULATE(
        COUNTROWS('Table'), 
        FILTER(
            ALL('Table'), 
            'Table'[team] = MAX('Table'[team])
        )
    )
RETURN _week / _total

 

Here is the result.

vnuocmsft_1-1708416387067.png

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

View solution in original post

7 REPLIES 7
Mohivaj
New Member

v-nuoc-msft
Community Support
Community Support

Hi @Mohivaj 

 

@Greg_Deckler  Thank you for sharing !

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"Table"

vnuocmsft_0-1708416304494.png

 

Create a measure. Calculate the average number of employees working on weekdays and weekends for different teams.

 

Average Employee = 
var _week = 
    CALCULATE(
        COUNTROWS('Table'), 
        FILTER(
            ALL('Table'), 
            'Table'[weektype] = MAX('Table'[weektype]) 
            && 
            'Table'[team] = MAX('Table'[team])
        )
    )
var _total = 
    CALCULATE(
        COUNTROWS('Table'), 
        FILTER(
            ALL('Table'), 
            'Table'[team] = MAX('Table'[team])
        )
    )
RETURN _week / _total

 

Here is the result.

vnuocmsft_1-1708416387067.png

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

Greg_Deckler
Super User
Super User

@Mohivaj So, what is the output you are looking for with that sample data and why? I mean, is it average employees per day per week type or by team per week type or ?


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

Thanks for the response @Greg_Deckler .

In the power BI visualization 

I wanted to show the weekend/weekday avg employee count in a bar chart so that we can find weekend or weekday employee count is more 

 

@Mohivaj I still don't know if I understand what you are asking for, an average over what? But, maybe you are looking for something like this:

Average Weekday =
  VAR __Table = SUMMARIZE( FILTER('Table', [weektype] = "weekday"), [date], "__Count", COUNTROWS('Table') )
  VAR __Result = AVERAGEX( __Table, [__Count])
RETURN
  __Result

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

Hi @Greg_Deckler I wanted  to visualize the average count of employees working on a weekday vs weekend for a team . If I choose team A I should be able to see the average count of employees working on a weekday and weekend

@Mohivaj What I provided should work then.


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

Top Solution Authors