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

Count rows with condition

Hello,

 

I am trying to count the number of termination using our pay period number as reference. Below is the datedim with the corresponding PayPeriod Number.

 

I need to display the count in a card but the catch is it is for the previous PayPeriod. For example we are in period 6 but what I need is the termination for period 5.

 

Thank you!

 

DatePayPeriodNumberYear
01/02/201942019
02/02/201942019
03/02/201942019
04/02/201942019
05/02/201942019
06/02/201942019
07/02/201942019
08/02/201942019
09/02/201942019
10/02/201942019
11/02/201942019
12/02/201942019
13/02/201942019
14/02/201942019
15/02/201952019
16/02/201952019
17/02/201952019
18/02/201952019
19/02/201952019
20/02/201952019
21/02/201952019
22/02/201952019
23/02/201952019
24/02/201952019
25/02/201952019
26/02/201952019
27/02/201952019
28/02/201952019
01/03/201962019
02/03/201962019
03/03/201962019
04/03/201962019
05/03/201962019
06/03/201962019
07/03/201962019
08/03/201962019
09/03/201962019
10/03/201962019
11/03/201962019
12/03/201962019
13/03/201962019
14/03/201962019

 

NumberNameStart DateEnd Date
1A01/01/201831/12/2154
2B01/01/201831/12/2154
3C01/01/201824/02/2019
4D01/01/201821/02/2019
5E01/01/201831/12/2154
6F01/01/201821/02/2019
7G01/01/201824/02/2019
8H01/01/201831/12/2154
9I01/01/201831/12/2154
10J01/01/201831/12/2154
1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @PatrickLamoste 

Tested with your two example table,

1. I name first table as "PayPeriod table", second as "employee table",

then i create a new table in Power BI, 

slicer period = SUMMARIZE('PayPeriod table','PayPeriod table'[Year],'PayPeriod table'[PayPeriodNumber])

These three tables have no relationships.

 

2. Add "year" and "period" column from 'slicer period' table in the slicer,

 

3. create measures in "PayPeriod table"

pre selected period = 
IF(MAX('PayPeriod table'[PayPeriodNumber])=SELECTEDVALUE('slicer period'[PayPeriodNumber])-1,1,0)

max = 
CALCULATE(MAX('PayPeriod table'[Date]),FILTER(ALL('PayPeriod table'),[pre selected period]=1))

min = 
CALCULATE(MIN('PayPeriod table'[Date]),FILTER(ALL('PayPeriod table'),[pre selected period]=1))

4. Create measures in "employee table",

condition = 
IF([min]>=MAX('employee table'[Start Date])&&[max]<=MAX('employee table'[End Date])

count = 
CALCULATE(DISTINCTCOUNT('employee table'[Number]),FILTER(ALL('employee table'),[condition]=1))

1.png

Please downloadmy pbix for more details.

 

Best Regards

Maggie

 

Community Support Team _ Maggie Li
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

3 REPLIES 3
v-juanli-msft
Community Support
Community Support

Hi @PatrickLamoste 

Tested with your two example table,

1. I name first table as "PayPeriod table", second as "employee table",

then i create a new table in Power BI, 

slicer period = SUMMARIZE('PayPeriod table','PayPeriod table'[Year],'PayPeriod table'[PayPeriodNumber])

These three tables have no relationships.

 

2. Add "year" and "period" column from 'slicer period' table in the slicer,

 

3. create measures in "PayPeriod table"

pre selected period = 
IF(MAX('PayPeriod table'[PayPeriodNumber])=SELECTEDVALUE('slicer period'[PayPeriodNumber])-1,1,0)

max = 
CALCULATE(MAX('PayPeriod table'[Date]),FILTER(ALL('PayPeriod table'),[pre selected period]=1))

min = 
CALCULATE(MIN('PayPeriod table'[Date]),FILTER(ALL('PayPeriod table'),[pre selected period]=1))

4. Create measures in "employee table",

condition = 
IF([min]>=MAX('employee table'[Start Date])&&[max]<=MAX('employee table'[End Date])

count = 
CALCULATE(DISTINCTCOUNT('employee table'[Number]),FILTER(ALL('employee table'),[condition]=1))

1.png

Please downloadmy pbix for more details.

 

Best Regards

Maggie

 

Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

v-juanli-msft
Community Support
Community Support

Hi @PatrickLamoste 

In case you are in period 6,

Would you like to calculate the count of distinct Name if their Start Date and End Date are in Period 5?

 

Best Regards

Maggie

Oh yeah I missed that part. I need to count it using distinct "Number" it's like an employee ID.

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.