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

Using Countrows based on multiple conditions

Hi,

 

I have a dataset with the following following columns, basically I just wanted to have a calculated column, that populates the number of actions when the Action is "Promotion" or "Secondment" or both for each employee. And for employee with no Separation Date, I want the count of the number of Promotion or Secondment or both when the Effective date is between today and 12 months ago. For employee with a Separation Date, the count should be when the Effective date equals or is greater than 12 months before the Separation Date and is less than the Separation Date.

Please see this dataset, the "No. of Promotion and Secondment last 12 months" is the calculated column I want:

Row

 

Employee NameEffective DateActionSeparation DateNo. of Promotion and Secondment last 12 months

1

Jane Jones8/02/2025Hire 0
2Carrie Bradshaw1/01/2024Secondment 2
3Carrie Bradshaw6/06/2024Promotion 2
4Carrie Bradshaw26/10/2021Secondment 2
5Rebecca Lynn16/10/2022Hire 1
6Rebecca Lynn14/10/2023Secondment 1
7Yao Ming7/10/2022Secondment7/06/20231
8Zoe Meng7/01/2024Add Worker 0
9Hoi Lou5/10/2021Hire2/02/20231
10Hoi Lou5/11/2021Secondment2/02/20231
11Hoi Lou6/06/2022Promotion2/02/20231

 

I did try this Dax code for the calculated column, but it only returns either 1 for row with Promotion or Secondment with the effective date and separation date condition. For example, for Carrie Bradshaw, it only returns 1 for the Row 2 and 3, and 0 for Row 4, but what I want is 2 for Row 2, 3 and 4.

No. of Promotion and Secondment last 12 months =
VAR CurrentEmployee = 'Data'[Employee Name]
VAR SeparationDate = 'Data'[Separation Date]
VAR EffectiveStartDate = 'Data'[Effective Date]
VAR Last12MonthsStartDate = TODAY() - 365
RETURN
IF(
ISBLANK(SeparationDate),
CALCULATE(
COUNTROWS('Data'),
'Data'[Employee Name] = CurrentEmployee,
('Data'[Action] = "Promotion" && 'Employment Action History'[Action] = "Secondment"),
'Data'[Effective Start Date] >= Last12MonthsStartDate
),
CALCULATE(
COUNTROWS('Data'),
'Data'[Employee Name] = CurrentEmployee,
('Data'[Action] = "Promotion" && 'Data'[Action] = "Secondment"),
'Data'[Effective Date] >= SeparationDate - 365,
'Data'[Effective Date] <= SeparationDate
)
)

Thanks in advance, much appreciated!

1 ACCEPTED SOLUTION

@Hyuna_8000 , Yes you can try using SUMX

 

No. of Promotion and Secondment last 12 months =
VAR CurrentEmployee = 'Data'[Employee Name]
VAR SeparationDate = 'Data'[Separation Date]
VAR Last12MonthsStartDate = TODAY() - 365

RETURN
IF(
ISBLANK(SeparationDate),
CALCULATE(
SUMX(
FILTER(
'Data',
'Data'[Employee Name] = CurrentEmployee &&
'Data'[Action] IN {"Promotion", "Secondment"} &&
'Data'[Effective Date] >= Last12MonthsStartDate
),
1
)
),
CALCULATE(
SUMX(
FILTER(
'Data',
'Data'[Employee Name] = CurrentEmployee &&
'Data'[Action] IN {"Promotion", "Secondment"} &&
'Data'[Effective Date] >= SeparationDate - 365 &&
'Data'[Effective Date] < SeparationDate
),
1
)
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

3 REPLIES 3
bhanu_gautam
Super User
Super User

@Hyuna_8000 , Try below DAX mentioned:-

 

No. of Promotion and Secondment last 12 months =
VAR CurrentEmployee = 'Data'[Employee Name]
VAR SeparationDate = 'Data'[Separation Date]
VAR EffectiveStartDate = 'Data'[Effective Date]
VAR Last12MonthsStartDate = TODAY() - 365

RETURN
IF(
ISBLANK(SeparationDate),
CALCULATE(
COUNTROWS('Data'),
'Data'[Employee Name] = CurrentEmployee,
'Data'[Action] IN {"Promotion", "Secondment"},
'Data'[Effective Date] >= Last12MonthsStartDate
),
CALCULATE(
COUNTROWS('Data'),
'Data'[Employee Name] = CurrentEmployee,
'Data'[Action] IN {"Promotion", "Secondment"},
'Data'[Effective Date] >= SeparationDate - 365,
'Data'[Effective Date] < SeparationDate
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Hi @bhanu_gautam 
Thanks for your prompt reply, really appreciated it! 
It still returns 1 for individual row that matches the criteria, instead of summing up or count the total rows that match the criteria. I wonder if I should use Sumx instead, so far no luck yet.

@Hyuna_8000 , Yes you can try using SUMX

 

No. of Promotion and Secondment last 12 months =
VAR CurrentEmployee = 'Data'[Employee Name]
VAR SeparationDate = 'Data'[Separation Date]
VAR Last12MonthsStartDate = TODAY() - 365

RETURN
IF(
ISBLANK(SeparationDate),
CALCULATE(
SUMX(
FILTER(
'Data',
'Data'[Employee Name] = CurrentEmployee &&
'Data'[Action] IN {"Promotion", "Secondment"} &&
'Data'[Effective Date] >= Last12MonthsStartDate
),
1
)
),
CALCULATE(
SUMX(
FILTER(
'Data',
'Data'[Employee Name] = CurrentEmployee &&
'Data'[Action] IN {"Promotion", "Secondment"} &&
'Data'[Effective Date] >= SeparationDate - 365 &&
'Data'[Effective Date] < SeparationDate
),
1
)
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

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