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
mikeborg82
Helper II
Helper II

DAX formulat - GroupBY?

I have the following DAX formula.  This gives me the average headcount as the measure implies for all of the workforce snapshots that append from the files in the folder I get the data from.

 

Average Headcount = CALCULATE(COUNT('Workforce Snapshots'[Employee Number]),DISTINCT('Workforce Snapshots'[Source.Name]))/DISTINCTCOUNT('Workforce Snapshots'[Source.Name])

 

Now, I want to get a formula to from the avg headcount get number of employees in each "Grade #".  I assume I need to use GROUPBY function.  But I can't seem to get it to work.  I am trying to use this as I overlay in a stacked and line chart (Terms by grade in colums) and I want to show the number of headcount by grade in the line.  

 

Thanks for any help.  

3 REPLIES 3
v-sihou-msft
Employee
Employee

@mikeborg82

 

To have your calculation "group by" some columns, you need to use ALLEXCEPT() function in CALCULATE.

 

Avg HeadCount Per Grade =
CALCULATE (
    COUNT ( Table1[EmpId] ),
    DISTINCT ( Table1[Source] ),
    ALLEXCEPT ( Table1, Table1[Grade] )
)
    / CALCULATE (
        DISTINCTCOUNT ( Table1[Source] ),
        ALLEXCEPT ( Table1, Table1[Grade] )
    )

4.PNG

 

Regards,

This would work in a normal visualization.  However, when I try to use this measure in the line values of a "Stacked column and Line chart", the line is now a straight line... essentially, the line value in this chart does not concern itself of the axis values

image.PNG

Greg_Deckler
Super User
Super User

Can you supply sample data? It seems like you could achieve what you want by putting Grade # in the Legend.


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