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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
aflintdepm
Helper III
Helper III

Count Rows on another table based on attributes on main table

I have 2 tables, one is a list of employees with employment status and the other is a list of tasks assigned to those employees with the task status.  Everthing is linked by EE_ID, but I did have to create a table of just unique values to avoid Many:Many between the 2 source tables, so my relationship looks like this:
Task Table *->1 Unique EE_ID 1<-* EE Status

 

I need create a measure that tells me the list of Incomplete tasks when an Employee is Terminated so those tasks can be reassigned.

 

I would like to present the results in a table or matrix.

 

Desired Ouput:

EE_IDNameStatusTask Count
1111John SmithTerminated2
2222Bob JonesTerminated0

 

EE_Status:

EE_IDNameStatus
1111John SmithTerminated
2222Bob JonesTerminated
3333Jane DoeActive

 

Task table:

EE_IDTask_NameTask_Status
1111VisitComplete
1111VisitIncomplete
1111EvalIncomplete
2222VisitComplete
2222VisitComplete
2222EvalComplete
3333VisitComplete
3333VisitIncomplete
3333EvalIncomplete
1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

Hi @aflintdepm ,

 

You could use below measure - 

 

Measure =
COUNTROWS (
    FILTER (
        'Task table',
        'Task table'[EE_ID] = MAX ( EE_Status[EE_ID] )
            && 'Task table'[Task_Status] = "Incomplete"
            && MAX ( EE_Status[Status] ) = "Terminated"
    )
) + 0

 

output -

Samarth_18_1-1721064263273.png

 

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

4 REPLIES 4
Sahir_Maharaj
Super User
Super User

Hello @aflintdepm,

 

Can you please try the following approach:

IncompleteTasksForTerminated = 
VAR TerminatedEmployees = 
    FILTER (
        'EE_Status',
        'EE_Status'[Status] = "Terminated"
    )

VAR IncompleteTasks = 
    FILTER (
        'Task Table',
        'Task Table'[Task_Status] = "Incomplete"
    )

VAR Result = 
    COUNTROWS (
        FILTER (
            'Task Table',
            'Task Table'[EE_ID] IN VALUES (TerminatedEmployees[EE_ID]) &&
            'Task Table'[Task_Status] = "Incomplete"
        )
    )

RETURN
    Result

Hope this helps!


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Samarth_18
Community Champion
Community Champion

Hi @aflintdepm ,

 

You could use below measure - 

 

Measure =
COUNTROWS (
    FILTER (
        'Task table',
        'Task table'[EE_ID] = MAX ( EE_Status[EE_ID] )
            && 'Task table'[Task_Status] = "Incomplete"
            && MAX ( EE_Status[Status] ) = "Terminated"
    )
) + 0

 

output -

Samarth_18_1-1721064263273.png

 

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

@Samarth_18 
Thank you for the response.  Can you please clarify the function of the MAX in the measure?  Other than that, I believe I understand the syntax

@aflintdepm , It's just to pick a value of EE_ID, Status from the current context.

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.