Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Power BI DAX - count occurence of ID

Hello,
I have a set of data with employee, ID and training details. I need to tag those employees who have completed the set of training under one Sales Strategy based on number of training's they did also taking into account the year they completed the training.

 IDNameTrainingEffective DateExpected results
2580Emplyee XSales Strategy – Execution30-06-2020 00:004
2580Emplyee XSales strategy – Practical30-06-2020 00:004
2580Emplyee XSales strategy – Explain30-06-2020 00:004
2580Emplyee XSales strategy – Welcome30-06-2020 00:004
2580Emplyee XSales strategy – Discern31-05-2020 00:001
1388Emplyee ZSales strategy – Practical31-05-2019 00:001
1388Emplyee ZSales strategy – Explain30-04-2020 00:002
1388Emplyee ZSales strategy – Welcome30-03-2020 00:002


So, to complete the Sales strategy course, the employee must complete 5 trainings:
Sales Strategy – Execution,Sales strategy – Practical,Sales strategy – Explain,Sales strategy – Welcome,Sales strategy – Discern.
Also, the year of completion matters. for example, X completed first 4 trainings in 2020 so the expected result in the column should be 4. In 2019,X completed 1 training under sales strategy category so expected result in the column should be 1.
Please help with the DAX as I am new to Power BI.

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

There are many ways of doing that, here's one example.

 

result = 
var e=SELECTEDVALUE(Table3[ID])
var y=year(SELECTEDVALUE(Table3[Effective Date]))
return CALCULATE(DISTINCTCOUNT(Table3[Training]),ALLSELECTED(Table3),Table3[ID]=e,YEAR(Table3[Effective Date])=y)

 

Note that your sample data does not match your expected results - Emplyee X  has completed 5 courses in 2020. 

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

There are many ways of doing that, here's one example.

 

result = 
var e=SELECTEDVALUE(Table3[ID])
var y=year(SELECTEDVALUE(Table3[Effective Date]))
return CALCULATE(DISTINCTCOUNT(Table3[Training]),ALLSELECTED(Table3),Table3[ID]=e,YEAR(Table3[Effective Date])=y)

 

Note that your sample data does not match your expected results - Emplyee X  has completed 5 courses in 2020. 

Anonymous
Not applicable

Thank you! This worked.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors