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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply

Understanding Headcount (Dax for Allexcept, All)

Hi All,

 

I have been tasked with creating a report that tracks headcount, attendance, etc. for employees. 

The first phase is understanding headcount - ie, how many people are coming onsite for a given time period. 

I'm sharing a subset for 3 employees for the month of Aug, 2024. Needless to say, there are 1000s of employees but I am focusing on these 3 to make sure my measures are working right (which aren't, which is why I am asking for help on this group ;(  ) 

 

 

Here is what I want to find and the dax funtions I used- 

 

1. UniqueBadgeIns Per Day

UniqueBadgeInsPerDay_Final 3 =
CALCULATE(
    DISTINCTCOUNT('Badging Data'[EmployeeID]),
    KEEPFILTERS(VALUES('Badging Data'[EnterBadgeDate])),
    KEEPFILTERS(VALUES('Badging Data'[Employee Full Name]))
)


2. UniqueBadgeIns Per Week: 

UniqueBadgeInsPerWeek =
CALCULATE(
    DISTINCTCOUNT('Badging Data'[EmployeeID]),
    ALLEXCEPT('Badging Data','Badging Data'[EnterBadgeDate]),
    VALUES('Badging Data'[WeekNumber])
)

3. UniqueBadgeIns Per Month:

UniqueBadgeInsPerMonth =
CALCULATE(
    DISTINCTCOUNT('Badging Data'[EmployeeID]),
    ALLEXCEPT('Badging Data', 'Badging Data'[EnterBadgeDate]),
    VALUES('Badging Data'[EnterBadgeDate].[Month])
)

4. UniqueBadgeIns Per Quarter: 

UniqueBadgeInsPerQuarter =
CALCULATE(
    DISTINCTCOUNT('Badging Data'[EmployeeID]),
    ALLEXCEPT('Badging Data', 'Badging Data'[EnterBadgeDate]),
    VALUES('Badging Data'[EnterBadgeDate].[Quarter])
)

 

Employee Full NameEmployeeIDEnterBadgeTimeSum of TotalMinutesEnterBadgeBuilding
E28/6/2024 8:25389229
M18/6/2024 8:37434223
E28/7/2024 8:41482229
M18/7/2024 9:04461223
D38/7/2024 9:08457223
M18/8/2024 8:35452229
E28/8/2024 8:42459229
D38/8/2024 9:11359223
M18/12/2024 7:2862223
M18/21/2024 7:41532223
E28/26/2024 9:41320229
M18/27/2024 13:35164223
M18/28/2024 8:29474229
E28/29/2024 9:54155229

 

Based on the dataset above, if I filtered for 8/6/2024, my measure for UniqueBadgeIns Per Day is returning a count of 3 instead of 2. 
I feel so disheartened that I find it hard to move forward with other requirements.

Can someone tell me what I'm doing wrong? 
Also, what If I were to slice this data by not just EnterBadgeData, but also - Business Group, Employee Name, Division, Unit, etc, ?

Eagerly awaiting guidance on this topic.

 

Thanks in advance to the community 🙂 

2 ACCEPTED SOLUTIONS
v-tangjie-msft
Community Support
Community Support

HI @anonymoususer92 ,

 

Thanks rajendraongole1  for the quick reply. I have some other thoughts to add:

1. This is my test data.  

vtangjiemsft_0-1726196326698.png

2.We can create a column.

EnterBadgeDate = DATEVALUE([EnterBadgeTime])

vtangjiemsft_1-1726196376734.png

3.We can create a date table.

Date = ADDCOLUMNS(CALENDAR(DATE(2024,1,1),DATE(2024,12,31)),"quarter",QUARTER([Date]),"month",MONTH([Date]),"weeknum",WEEKNUM([Date],2))

vtangjiemsft_2-1726196416946.png

4. We can create a measure.

UniqueBadgeIns = 
CALCULATE(
    DISTINCTCOUNT('Badging Data'[EmployeeID]),ALLSELECTED('Badging Data'))

5.Then the result is as follows.

vtangjiemsft_3-1726196818813.pngvtangjiemsft_4-1726196831164.pngvtangjiemsft_5-1726196847114.pngvtangjiemsft_6-1726196905697.png

If I've misunderstood you please point it out in a follow-up reply.

 

Best Regards,

Neeko Tang

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

Hi @anonymoususer92 ,

 

Try to:
1. Change the model relationship to a one-to-many relationship in one direction
2. Click the [employee name+id] slicer and set the interaction to "None" on the card visual.

Change how visuals interact in a report - Power BI | Microsoft Learn

vtangjiemsft_0-1726638817651.pngvtangjiemsft_1-1726638856008.png

If that doesn't help, please provide your PBIX file (please note the protection of private data).

 

Best Regards,

Neeko Tang

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

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

In the Power Query Editor, seperate the time stamp in another column so that you have only the date data type in a column.  Create a Calendar Table with calculated column formulas for Year, Month name, Month number and Quarter.  Sort the Month name by the Month number.  Create a relationship (Many to One and Single) from the Date column (created as per the first sentence i wrote) to the Date column of the Calendar Table.  To any visual, drag any date dimension from the Calendar Table.  Drag this measure

Measure = distinctcount('Badging data'[EmployeeID])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-tangjie-msft
Community Support
Community Support

HI @anonymoususer92 ,

 

Thanks rajendraongole1  for the quick reply. I have some other thoughts to add:

1. This is my test data.  

vtangjiemsft_0-1726196326698.png

2.We can create a column.

EnterBadgeDate = DATEVALUE([EnterBadgeTime])

vtangjiemsft_1-1726196376734.png

3.We can create a date table.

Date = ADDCOLUMNS(CALENDAR(DATE(2024,1,1),DATE(2024,12,31)),"quarter",QUARTER([Date]),"month",MONTH([Date]),"weeknum",WEEKNUM([Date],2))

vtangjiemsft_2-1726196416946.png

4. We can create a measure.

UniqueBadgeIns = 
CALCULATE(
    DISTINCTCOUNT('Badging Data'[EmployeeID]),ALLSELECTED('Badging Data'))

5.Then the result is as follows.

vtangjiemsft_3-1726196818813.pngvtangjiemsft_4-1726196831164.pngvtangjiemsft_5-1726196847114.pngvtangjiemsft_6-1726196905697.png

If I've misunderstood you please point it out in a follow-up reply.

 

Best Regards,

Neeko Tang

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

Thank you @v-tangjie-msft Neeko! 

This measure works great when I used the data set you provided ! 

A few points -

1. When I used the above measure on my actual data, it is still giving a count of 3 for 6th of Aug. It is so weird. (See screenshots). And it is the employee with alias name 'D' that is causing this issue. Could this be because I am using another slicer  called 'Emp Full + ID' ?

anonymoususer92_0-1726628202788.png

 

anonymoususer92_1-1726628234718.png

 

 

2. Could it be because I changed the relationship between date table (I have a custom date table too) and Badging data to Bi-directional? 

3. If you look at your last screenshot, it is showing a count of 3 instead of 2! What do you think happened there? 

Hi @anonymoususer92 ,

 

Try to:
1. Change the model relationship to a one-to-many relationship in one direction
2. Click the [employee name+id] slicer and set the interaction to "None" on the card visual.

Change how visuals interact in a report - Power BI | Microsoft Learn

vtangjiemsft_0-1726638817651.pngvtangjiemsft_1-1726638856008.png

If that doesn't help, please provide your PBIX file (please note the protection of private data).

 

Best Regards,

Neeko Tang

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

It worked! The issue I found was that the Sum of Total Minutes had blank values that prevented rows showing up in a table. I changed that in the Power Query from Blank to 0. That seemed to pull up the records on a table.

 

Let me ask you this now - 

 

 

anonymoususer92_1-1726797072794.png

 

 

If I use the unique badge in measure, I get count (Business Group, Division, even Quarters) as the same value (which is the total unique badge ins). See first image.

 

But I'd like for it to be like the below image - 

 

anonymoususer92_2-1726797209971.png

 

Thanks again Neeko! 

Hi @anonymoususer92 ,

 

Glad to hear that your issue has been resolved. Sorry for that the information you have provided is not making the problem clear to me. 

In order to solve your new problem , please create a new case with a detailed description ,we suggest a case to solve only one problem, because it can get good help and give a better reference for other users!

 

Best Regards,

Neeko Tang

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

rajendraongole1
Super User
Super User

Hi @anonymoususer92 -create a below measure calculate the distinct number of employees who badged in on a given day , i am using selectedvalue function. as we have slicer to report 

 

UniqueBadgeInsPerDay_Final =
CALCULATE(
DISTINCTCOUNT('Badging Data'[EmployeeID]),
FILTER(
'Badging Data',
'Badging Data'[EnterBadgeDate] = SELECTEDVALUE('Badging Data'[EnterBadgeDate])
)
)

 

Create measure for weekly, monthly, and quarterly calculations,instead of use of ALLEXCEPT and VALUES might be causing duplication or incorrect filtering

UniqueBadgeInsPerWeek =
CALCULATE(
DISTINCTCOUNT('Badging Data'[EmployeeID]),
FILTER(
'Badging Data',
'Badging Data'[EnterBadgeDate] IN DATESINPERIOD(
'Badging Data'[EnterBadgeDate],
MAX('Badging Data'[EnterBadgeDate]),
-7,
DAY
)
)
)

 

Monthly:

UniqueBadgeInsPerMonth =
CALCULATE(
DISTINCTCOUNT('Badging Data'[EmployeeID]),
FILTER(
'Badging Data',
MONTH('Badging Data'[EnterBadgeDate]) = MONTH(SELECTEDVALUE('Badging Data'[EnterBadgeDate]))
)
)

 

Quarterly:

UniqueBadgeInsPerQuarter =
CALCULATE(
DISTINCTCOUNT('Badging Data'[EmployeeID]),
FILTER(
'Badging Data',
QUARTER('Badging Data'[EnterBadgeDate]) = QUARTER(SELECTEDVALUE('Badging Data'[EnterBadgeDate]))
)
)

if you add a slicer for Business Group, the DISTINCTCOUNT measure will return the distinct badge-ins for employees in that group only.

please check on the EmployeeID and EnterBadgeDate are properly filtered so that only distinct badge-ins per day are counted.

 

Above measure helps in your scenerio.





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

Proud to be a Super User!





Thanks @rajendraongole1 !

So I used the measure UniqueBadgeInsPerDay_Final that you created. 
While it is able to filter based on emp_id selected, it doesn't account for a particular 'date'
If you look at the data I shared, if i select 6th Aug from the slicer, and then slice for all 3 employees, it gives me a count fo 3 (In KPI Card) instead of 2. I think it the function is missing the ability to slice by date along with emp_id

 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors
Top Kudoed Authors