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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Lad25
New Member

DAX Formula to count if value is contained in another column

Hi everyone.

 

I've been searching for ways to do this, but haven't found anything yet.

 

I have 2 tables, one has a list of Products that we sell (1 column, unique values), while the other table has the results of a survey made to a sample of clients, which have all of the products that each client is selling in a field, sepparated by comma.

 

Here is an example of what I have

 

 

Products Table

Products
Product A
Product B
Product C
Product D

 

Survey table

ClientRegistered products for sale
Client AProduct A, Product B, Product D
Client BProduct B, Product C
Client CProduct A, Product D
Client DProduct B
Client EProduct A, Product B, Product C, Product D

 

What I'm trying to achieve is something similar to this

ProductCount
Product A3
Product B4
Product C2
Product D3

 

I managed to obtain a table with a calculated column that outputs the Count, but the issue is that I want to filter by the client name, to see which products he doesn't sell, and the filter doesn't change the calculations. I tried relating the tables, but since the values are comma separated, the calculations weren't correct.

The DAX Formula for the calculated column I'm using is the following (TDatos is the survey table in the example above, and TSKU is the product table):

 

Column = CALCULATE (
    COUNTROWS ( TDatos ),
    FILTER (
        ALLSELECTED ( TDatos ),
        CONTAINSSTRING ( TDatos[SKU vendidos], TSKU[SKU] )
    )
)

 

Any hints are appreciated, thanks!

1 ACCEPTED SOLUTION
sevenhills
Super User
Super User

Assuming you tables are "Products", "Clients", and they are not related:

 

sevenhills_0-1729722006735.png

 

sevenhills_1-1729722024809.png

 

Add measure to Products table

M1 = 

var _c = SELECTEDVALUE(Products[Products])

RETURN COUNTROWS( filter( ALLSELECTED(Clients), CONTAINSSTRING( Clients[Registered products for sale], _c)))

 

Sample output 

*no selection of client*

sevenhills_2-1729722155792.png

*select clients*

sevenhills_3-1729722203897.png

 

Hope it helps!

 

View solution in original post

3 REPLIES 3
sevenhills
Super User
Super User

Assuming you tables are "Products", "Clients", and they are not related:

 

sevenhills_0-1729722006735.png

 

sevenhills_1-1729722024809.png

 

Add measure to Products table

M1 = 

var _c = SELECTEDVALUE(Products[Products])

RETURN COUNTROWS( filter( ALLSELECTED(Clients), CONTAINSSTRING( Clients[Registered products for sale], _c)))

 

Sample output 

*no selection of client*

sevenhills_2-1729722155792.png

*select clients*

sevenhills_3-1729722203897.png

 

Hope it helps!

 

Thanks! This is exactly what I needed, much appreciated

Glad it helped!

 

Optional: appreciate if you can give kudos 🙂 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors