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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
grdi
Frequent Visitor

SUMIFS function for unrelated tables using CONTAINS

I have 2 tables that are unrelated.  Essentially an employee master table, a table that essentially logs activities and assigns Yes No values.  If multiple employees perform the activity, for whatever reason, they are input into the field seperated by comma.  And no, there is no detail table that breaks them out.  

So what I want to do is to create measures that will look at the master table, and do either a SumIfs or CountIfs style function to see if their ID appears in the column, and sum the columns.  One measure for each of Yes and No in the example data.  

 

So an example of the master data:

 

empIDempName
A1B2John
C3D4Jack
E5F6Jane
G7H8Janet

 

 

Then how it shows in the activity table:

ActivityYesNo
A1B210
C3D4, A1B201
C3D4, A1B2, G7H810
E5F601

 

And what I'd like to have as the result.

empIDempNameYESNO
A1B2John21
C3D4Jack11
E5F6Jane01
G7H8Janet10

 

In Excel, it would be something like =SUMIFS(columnYES,columnActivity,"*"&field_empID&"*")

 

I'm trying to create a measure on the Employee Master table in the PowerBI data that does something like that.  But because of the lack of relationship it's not working correctly.  

Thanks for the help.

1 ACCEPTED SOLUTION
danextian
Super User
Super User

Hi @grdi 

 

Try this:

Sum of Yes = 
CALCULATE (
    SUM ( activityTable[Yes] ),
    KEEPFILTERS (
        CONTAINSSTRING ( activityTable[Activity], SELECTEDVALUE ( empTable[empID] ) )
    )
)

danextian_1-1743148416638.png

 

Change the column name for the sum of no.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

View solution in original post

3 REPLIES 3
danextian
Super User
Super User

Hi @grdi 

 

Try this:

Sum of Yes = 
CALCULATE (
    SUM ( activityTable[Yes] ),
    KEEPFILTERS (
        CONTAINSSTRING ( activityTable[Activity], SELECTEDVALUE ( empTable[empID] ) )
    )
)

danextian_1-1743148416638.png

 

Change the column name for the sum of no.

 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thanks for the reply @danextian .  I'm using your formula but not getting the correct results.  For some reason I'm only getting a count of 1 for one employee.  And I know there should be about 15 employees with a combined total of 60+ for this calculation.  Also odd that the name shows one but the total is 208.  I think those are the ones with no match?  Which is possible as well as this is supposed to only be for a specific subset of employees.  Here is the code I'm using and the result I'm getting.

 

grdi_0-1743162793622.png

 

grdi_1-1743162886049.png

EDITING HERE:  I beleive an existing relationship with another column is what was causing my formula not to work as the solution.  I uploaded a duplicate table with the additional columns that formed the relationship removed, and it worked as intended.  So solution is good and will mark it as such.  Wanted to include the edit for future reference for others searching.  

 

Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1743130985518.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.

Top Solution Authors