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
bigchippah
Helper I
Helper I

Calculating Audit Completions over time from Changing Roster of Employees

Hello,

I am trying to calculate the number/percentage of audits of a team as they are audited over a time period.  I have been struggling with an efficient way to accomplish this task and I'm not making any more progress.  I apologize in advance, because this is a long one.  Here's what I'm working with:

My sources:

  • I receive a weekly list of current employees.  These are saved in a OneDrive folder and merged in PowerQuery to give me an overall roster of employees from week to week.
  • Employees are audited for food safety at various times through the month.  The list of audits are received as a spreadsheet weekly.  This is a single file that is updated as audits are conducted.

Table 1. Employee Roster:

DateEmployee IDDepartment
2/27Employee1Produce
2/27Employee2Produce
2/27Employee3Deli
2/27Employee4Deli
2/27Employee5Produce
2/27Employee6Bakery
2/27Employee7Bakery
2/20Employee1Produce
2/20Employee2Produce
2/20Employee3Deli
2/20Employee8Deli
2/20Employee9Deli
2/20Employee10Bakery

 

I have a measure to calculate the number of employees in each department.  I use COUNTROWS to return a roster size by department:

Measure Result - Department Employee Count:

DateDepartment# of Employees
2/27Produce3
2/27Deli2
2/27Bakery2
2/20Produce2
2/20Deli3
2/20Bakery1

 

These employees are periodically audited for cleanliness.

Table 2. Audit Results:

DateEmployeeDepartmentResult
2/27Employee1ProducePass
2/21Employee4DeliPass
2/20Employee2ProducePass
2/19Employee8DeliFail
2/15Employee7BakeryPass

 

My desired outcome:

  • Be able to calculate weekly how many/percentage of employees of each department have been audited as the month progresses.
  • If an employee is audited during the measuring period, I would like to remove them from the list of remaining employees

 

Slicers: Date Slicer (choose week/month/quarter)

DatesDepartment# of Employees (as of first date of measuring period)AuditedRemaining
2/1 - 2/27Deli321
2/1 - 2/27Bakery211
2/1 - 2/27Produce312
2/1 - 2/19Deli312
2/1 - 2/19Bakery211
2/1 - 2/19Produce303

 

My challenge(s):

  • Employee roster numbers change from week to week.  Week 1 (2/20) might have 6 employees, while Week 2 (has 7 employees).  I can't SUM my roster because some employees show up on both weeks.
  • I can compromise by getting the roster sizes at the beginning of the measuring period (date of the first audit of the month) and using it as my constant. How can I get a COUNTROWS value for the earliest date in a dateslicer period?
  • How can I compare my audited list to my initial roster and remove those who have been audited?

Thank you for reading, and thank you for any guidance you may be able to provide!

3 REPLIES 3
bigchippah
Helper I
Helper I

@v-yangliu-msft  Can you provide any more clarification on your proposed solution?  I would greatly appreciate it!

bigchippah
Helper I
Helper I

@v-yangliu-msftHello and thank you for the answer!  I'm trying to work my way through the steps and I've encountered a couple of error messages:
In the "Add a week and count to Audit Results" step, the following code:

count = COUNTX(FILTER(ALL('Audit Results'),'Audit Results'[week]=EARLIER('Audit Results'[week])&&'Audit Results'[Department]=EARLIER('Audit Results'[Department])),[Department])

returns an error that says, "EARLIER/EARLIEST refers to an earlier row context which doesn't exist."

Secondly, when I use this code:

Audited =
var _min=MINX(ALLSELECTED('Audit Results'),'Audit Results'[Date])
var _max=MaxX(ALLSELECTED('Audit Results'),'Audit Results'[Date])
return
CALCULATE(SUM('Audit Results'[Column]),FILTER(ALL('Audit Results'),MAX('Audit Results'[week])>=WEEKNUM(_min,1)&&MAX('Audit Results'[week])<=WEEKNUM(_max,1)&&'Audit Results'[Department]=MAX('Employee Roster'[Department])))

can you clarify which column 'Audit Results'[Column] should use? 

Thank you for your time and assistance!  I am very greatful!

v-yangliu-msft
Community Support
Community Support

Hi  @bigchippah ,

Here are the steps you can follow:

1. Create calculated table.

Table = CALENDAR(DATE(2022,1,1),DATE(2022,12,31))

vyangliumsft_0-1651134170174.png

2. Create calculated column.

Add a week and count to Audit Results:

week = WEEKNUM('Employee Roster'[Date],1)
count = COUNTX(FILTER(ALL('Audit Results'),'Audit Results'[week]=EARLIER('Audit Results'[week])&&'Audit Results'[Department]=EARLIER('Audit Results'[Department])),[Department])

vyangliumsft_1-1651134170176.png

Add a week to Employee Roster:

week = WEEKNUM('Employee Roster'[Date],1)

vyangliumsft_2-1651134170177.png

3. Create measure.

# of Employees =
var _min=MINX(ALLSELECTED('Audit Results'),'Audit Results'[Date])
var _max=MaxX(ALLSELECTED('Audit Results'),'Audit Results'[Date])
return
COUNTX(FILTER(ALL('Employee Roster'),
'Employee Roster'[week] >=WEEKNUM(_min,1)&&
'Employee Roster'[week] <=WEEKNUM(_max,1)&&
'Employee Roster'[Department]=MAX('Employee Roster'[Department])&&
'Employee Roster'[week]=MAX('Employee Roster'[week])
),[Department])
Audited =
var _min=MINX(ALLSELECTED('Audit Results'),'Audit Results'[Date])
var _max=MaxX(ALLSELECTED('Audit Results'),'Audit Results'[Date])
return
CALCULATE(SUM('Audit Results'[Column]),FILTER(ALL('Audit Results'),MAX('Audit Results'[week])>=WEEKNUM(_min,1)&&MAX('Audit Results'[week])<=WEEKNUM(_max,1)&&'Audit Results'[Department]=MAX('Employee Roster'[Department])))

4. Result:

Take the [Date] of the Table table as the slicer.

vyangliumsft_3-1651134170178.png

 

Best Regards,

Liu Yang

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

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.