The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi all,
I'm looking to write a measure that calculates the average number of jobs an employee works per day (they may work one or more than one job per day). I'm not interested in days where they don't work (i.e., the average should only include dates in which they work). It will be easiest to just show you what I'm trying to achieve with some sample data. Looking for the code that will get me the bolded results below.
Dataset: | ||
Job Number | Date Worked | Employee # |
26527 | 10/1/2015 | Employee 1 |
26527 | 10/2/2015 | Employee 1 |
28266 | 10/1/2015 | Employee 2 |
29296 | 10/1/2015 | Employee 2 |
28012 | 10/2/2015 | Employee 2 |
27708 | 10/5/2015 | Employee 2 |
28266 | 10/5/2015 | Employee 2 |
26353 | 10/1/2015 | Employee 3 |
26803 | 10/1/2015 | Employee 3 |
26803 | 10/2/2015 | Employee 3 |
26803 | 10/3/2015 | Employee 3 |
Desired Results: | ||
Employee | Average # of Distinct Jobs per Day | Days Worked |
Employee 1 | 1.0 | 2 |
Employee 2 | 1.7 | 3 |
Employee 3 | 1.3 | 3 |
Thanks in advance for your help!
Solved! Go to Solution.
This should give you the desired output
Average # of Distinct Jobs per Day = DIVIDE ( CALCULATE ( COUNTA ( 'Table'[Job Number] ), ALLEXCEPT ( 'Table', 'Table'[Employee #] ) ), DISTINCTCOUNT ( 'Table'[Date Worked] ), 0 )
This should give you the desired output
Average # of Distinct Jobs per Day = DIVIDE ( CALCULATE ( COUNTA ( 'Table'[Job Number] ), ALLEXCEPT ( 'Table', 'Table'[Employee #] ) ), DISTINCTCOUNT ( 'Table'[Date Worked] ), 0 )