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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

Count employees in Year-Mo format by Month or Quarter or Year

Hi everyone,

 

I have a set of monthly employee records and I'm looking to create a measure that will allow me count/average the number of employees by Month or Year or Quarter depending on which Date Table fields I put into the Columns. 

 

My data looks like this:

Year-MoNameTeam
202006BobAlpha
202006GeorgeAlpha
202006SteveAlpha
202006SamAlpha
202006AliceAlpha
202006JaneBravo
202006KateBravo
202006RickBravo
202005BobAlpha
202005GeorgeAlpha
202005SteveAlpha
202005SamAlpha
202005AliceBravo
202004BobAlpha
202004GeorgeAlpha
202004SteveAlpha
202004SamAlpha

 

 

My desire would be to create outputs like this:

 

Output 1

(Straight count for monthly)

 202004202005202006
Alpha445
Bravo013

 

Output 2

(Average for quarter or year)

 Q2-2020
Alpha4.33
Bravo1.33

 

I am able to get Output 1 using a calculate(count) measure and linking the Year-Mo to my date table. However, I'm unsure how to do the second one -- if I change the Column to Quarter, my output is a sum of the Year-Mo data and not an average. 

 

Thank you!

 

1 ACCEPTED SOLUTION
edhans
Super User
Super User

Hi @Anonymous 

You are on the right track with a date table. I added a DateKey field to your data using the year and month. I just made it the first of the month then joined to the date table. Then I used this measure to get the average. Note that the totals in the matrix may not appear correct, but it is looking at the total year. It may not be relevant, in which case I'd just remove the total if the annual total average isn't helpful.

This would be fully dynamic. You could drop months, quarters, semesters, whatever and it would continue to show th average per month. It wouldn't work for days and weeks as those are below the granularity of what you are measuring - monthly average.

 

 

Average Teams = 
VAR TeamCount = COUNTROWS(Teams)
VAR MonthCount = DISTINCTCOUNT('Date'[Month])
RETURN
    DIVIDE(
        TeamCount,
        MonthCount,
        0
    )

 

 

It returns this:

2020-06-05 07_58_12-Untitled - Power BI Desktop.png

 

You can see what I did in the DateKey field in Power Query, and how my date table is structured in this PBIX file.

Creating a Dynamic Date Table in Power Query



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

5 REPLIES 5
edhans
Super User
Super User

Hi @Anonymous 

You are on the right track with a date table. I added a DateKey field to your data using the year and month. I just made it the first of the month then joined to the date table. Then I used this measure to get the average. Note that the totals in the matrix may not appear correct, but it is looking at the total year. It may not be relevant, in which case I'd just remove the total if the annual total average isn't helpful.

This would be fully dynamic. You could drop months, quarters, semesters, whatever and it would continue to show th average per month. It wouldn't work for days and weeks as those are below the granularity of what you are measuring - monthly average.

 

 

Average Teams = 
VAR TeamCount = COUNTROWS(Teams)
VAR MonthCount = DISTINCTCOUNT('Date'[Month])
RETURN
    DIVIDE(
        TeamCount,
        MonthCount,
        0
    )

 

 

It returns this:

2020-06-05 07_58_12-Untitled - Power BI Desktop.png

 

You can see what I did in the DateKey field in Power Query, and how my date table is structured in this PBIX file.

Creating a Dynamic Date Table in Power Query



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
Anonymous
Not applicable

Thank you very much @edhans    

This works beautifully 🙂

Great @Anonymous - glad it helped.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
ryan_mayu
Super User
Super User

@Anonymous 

 

First create a new column.

 

year-Q = 
VAR month=RIGHT(Sheet9[Year-Mo],2)
VAR Q = if(month in {"01","02","03"},"Q1",if(month in {"04","05","06"},"Q2",if(month in {"07","08","09"},"Q3","Q4")))
return left(Sheet9[Year-Mo],4)&Q

 

1.PNG

 

Then create a measure

 

average = COUNT(Sheet9[Name])/3

 

2.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

Thanks @ryan_mayu 

 

I wonder if there's a way to do this more dynamically? Ultimately this is going to be a tool for others to use and if I can get away with using a single measure that can count if we are looking at it monthly and average if we are looking at it quarterly or yearly, that would be very useful so as people build their own reports, it's a single "Employee count" measure vs. having three separate measures for monthly, quarterly, and yearly counts. 

 

I have a date table in my model that have things like "Year-Mo", "Quarter-Year", "Year" defined. My ideal would if then if I drop in "Year-Mo" into the column, it'll do the simple count of the Year-Mo employee table; if I drop in "Quarter-Year", it'll do the average. Is that possible? 

 

Thanks in advance!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors
Top Kudoed Authors