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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
msimmonsmcse
Helper I
Helper I

Need help counting rows on tables that are not directly related

I have a data model that contains 3 tables: Tickets, Time Entry, and Members

 

  • Tickets and Members have a 1:* relationship witht the Time Entry table. 
  • Each row in Members has a unique MemberID
  • Each row in Tickets has a unique ServiceTicketRecID.
  • Each row in Time Entry is related by MemberID and ServiceTicketRecID respectively
  • Each row in Tickets also has a ResourceList column that contains one or more MemberIDs in a string datatype. The column can contain one or more MemberIDs

 

I want to created a caluated column called Assigned Ticket Count for each row of the Member table. Here is the formula I tried first:

 

Assigned Ticket Count = CALCULATE(COUNT(Tickets[ServiceTicketRecId]), CONTAINS(Tickets,Tickets[ResourceList], 'Member'[MemberId])=TRUE())
 
However, I got an error "A function 'CONTAINS' has been used in a True/False expression that is used as a table filter expression. This is not allowed."

 

So I tried:

 

Assigned Ticket Count = CALCULATE(COUNT(Tickets[ServiceTicketRecId]), FILTER(Tickets,CONTAINS(Tickets,Tickets[ResourceList], 'Member'[MemberId])=TRUE()))
 
Now I am getting the same numbe in all rows; its probably the total number of rows in the Tickets table. How do I get this to show the correct number of Tickets that contain the MemberID in the ResourceList field for each row in Members?
1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @msimmonsmcse 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Tickets:

c1.png

 

Members:

c2.png

 

You may create a calculated column as below.

Assigned Ticket Count = 
var _result = 
COUNTROWS(
    FILTER(
        Tickets,
        CONTAINSSTRINGEXACT([ResourceList],EARLIER('Members'[MemberID]))
    )
)
return
IF(
    ISBLANK(_result),
    0,
    _result
)

 

Result:

c3.png

 

Best Regards

Allan

 

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-alq-msft
Community Support
Community Support

Hi, @msimmonsmcse 

 

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Tickets:

c1.png

 

Members:

c2.png

 

You may create a calculated column as below.

Assigned Ticket Count = 
var _result = 
COUNTROWS(
    FILTER(
        Tickets,
        CONTAINSSTRINGEXACT([ResourceList],EARLIER('Members'[MemberID]))
    )
)
return
IF(
    ISBLANK(_result),
    0,
    _result
)

 

Result:

c3.png

 

Best Regards

Allan

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Worked great, thank you for supplying a solution instead of simply giving instructions on how to ask the question. Sometimes beginners dont even know what they are asking for. I appreciate it!

Greg_Deckler
Super User
Super User

@msimmonsmcse - Having trouble following this. Sample data would help but in theory, something like:

 

Column = 
  COUNTROWS(FILTER('Other Table',[column in other table]=[column in this table] && [another column in the other table] = [another column in this table]))

Otherwise,

Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.