Forum Discussion
Need help creating a measure
Hello,
My data looks like this:
| Employee | Group | Date | Leave |
| 112 | Finance | 1/7/2025 | 1 |
| 112 | Finance | 1/8/2025 | 1 |
| 112 | Finance | 1/11/2025 | 1 |
| 112 | Finance | 1/12/2025 | 1 |
| 112 | Finance | 2/10/2025 | 1 |
| 113 | IT | 1/4/2025 | 1 |
| 113 | IT | 2/1/2025 | 1 |
| 114 | IT | 1/2/2025 | 1 |
| 114 | IT | 1/3/2025 | 1 |
| 114 | IT | 1/4/2025 | 1 |
I need a measure to show me the number of employees in the finance group that took leave more than 3 times. I'm going to use this measure in a visual that breaks out by month so expected result is 1 employee for January.
I tried the below but it's incorrect:
My apologies but I'm trying to calculate it by month. Example below.
Employee Group Date Leave 101 Finance 2/12/2025 1 101 Finance 2/13/2025 1 101 Finance 2/14/2025 1 101 Finance 2/15/2025 1 101 Finance 2/16/2025 1 101 Finance 3/20/2025 1 101 Finance 3/21/2025 1 101 Finance 3/22/2025 1 107 IT 1/22/2025 1 107 IT 1/23/2025 1 107 IT 1/24/2025 1 107 IT 1/25/2025 1 107 IT 2/3/2025 1 107 IT 2/4/2025 1 108 IT 2/1/2025 1 108 IT 2/2/2025 1 108 IT 2/3/2025 1 108 IT 2/4/2025 1 112 Finance 1/7/2025 1 112 Finance 1/8/2025 1 112 Finance 1/11/2025 1 112 Finance 1/12/2025 1 112 Finance 2/10/2025 1 113 IT 1/4/2025 1 113 IT 2/1/2025 1 114 IT 1/2/2025 1 114 IT 1/3/2025 1 114 IT 1/4/2025 1 120 Finance 1/2/2025 1 120 Finance 1/4/2025 1 120 Finance 2/1/2025 1 120 Finance 2/3/2025 1 132 Finance 1/2/2025 1 132 Finance 1/4/2025 1 132 Finance 1/5/2025 1 132 Finance 1/6/2025 1 132 Finance 2/3/2025 1 132 Finance 2/4/2025 1 132 Finance 2/5/2025 1 132 Finance 3/2/2025 1 132 Finance 3/3/2025 1 132 Finance 3/4/2025 1 I should see 2 employees for January and 1 for February for a total of 3 as highlighted in red above.
Here is the result from your measure:
Hi buttercream here ISINSCOPE handles the total row correctly by summing the monthly values instead of recalculating across all months. Sharing the PBIX file for reference.
buttercream
Assuming you have a period column the following DAX expression should give you what you're looking for:Finance Emp 3+ Leaves = VAR _Group = "FINANCE" VAR _Base = SUMMARIZE( CALCULATETABLE( 'Table', 'Table'[Group] = _Group ), [Employee], [Period] ) VAR _CheckLeave = FILTER( ADDCOLUMNS( _Base, "Leave", VAR _Emp = [Employee] VAR _Period = [Period] RETURN CALCULATE(SUM('Table'[Leave]), 'Table'[Employee] = _Emp, 'Table'[Period] = _Period) ), [Leave] > 3 ) RETURN COUNTROWS(_CheckLeave)I've attached a sample pbix for you.
14 Replies
- techies
Super User
Hi buttercream please try this
Finance Employees With 3+ Leaves = VAR EmpTable =ADDCOLUMNS(VALUES(LeaveData[Employee]),"LeaveCount",CALCULATE(SUM(LeaveData[Leave]),LeaveData[Group] = "Finance"))RETURNCOUNTROWS(FILTER(EmpTable, [LeaveCount] > 3))- buttercream
Helper II
Thanks. Almost works. The measure is ignoring the LeaveData[Group] = "Finance" and instead giving me the count for all groups.
- techies
Super User
Hi buttercream please try this
Finance Employees With 3+ Leaves = VAR FinanceEmployees =FILTER(VALUES(LeaveData[Employee]),CALCULATE(COUNTROWS(LeaveData), LeaveData[Group] = "Finance") > 0)VAR EmpTable =ADDCOLUMNS(FinanceEmployees,"LeaveCount",CALCULATE(SUM(LeaveData[Leave]),LeaveData[Group] = "Finance"))RETURNCOUNTROWS(FILTER(EmpTable, [LeaveCount] > 3))
- Ashish_Mathur
Super User
- buttercream
Helper II
Thanks. This is working but how do I add finance group only to the measure?
- Ashish_Mathur
Super User
You are welcome. What do you mean?
- cengizhanarslan
Super User
Please try the logic below:
Measure = VAR EmpSummary = SUMMARIZE( FILTER( 'Table', 'Table'[Group] = "Finance" ), 'Table'[Employee], "LeaveCount", SUM( 'Table'[Leave] ) ) RETURN COUNTROWS( FILTER( EmpSummary, [LeaveCount] > 3 ) ) - hnguy71
Super User
buttercream
Assuming you have a period column the following DAX expression should give you what you're looking for:Finance Emp 3+ Leaves = VAR _Group = "FINANCE" VAR _Base = SUMMARIZE( CALCULATETABLE( 'Table', 'Table'[Group] = _Group ), [Employee], [Period] ) VAR _CheckLeave = FILTER( ADDCOLUMNS( _Base, "Leave", VAR _Emp = [Employee] VAR _Period = [Period] RETURN CALCULATE(SUM('Table'[Leave]), 'Table'[Employee] = _Emp, 'Table'[Period] = _Period) ), [Leave] > 3 ) RETURN COUNTROWS(_CheckLeave)I've attached a sample pbix for you.
- buttercream
Helper II
This works. Wow. Thank you.