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
Anonymous
Not applicable

Counting Columns with specific criteria in a related table

Hello everyone,

 

I'm very new to Power Pivot and DAX. I've started looking into the subject as I've got an assignment with way to much data for a usual excel.

I can't figure out the proper syntax for two columns I want.

So, I've 3 tables with table 3 being a sort of reporting dashboard. I've figured out the 2nd column of my dashboard using =COUNTROWS(RELATEDTABLE('Table 1')) but I'm lost for the other 2 columns (N. of IDs with products) and (N. of Product 1 at Level 2).

 

Table 1

IDSegment
id01A
id02B
id03A
id04C
id05B
id06B
id07A

 

Table 2

IDProduct 1Product 2Product 3
id01Level 1Level 3 
id02Level 4Level 1Level 2
id03Level 2  
id04   
id05   
id06Level 2Level 2Level 1
id07Level 3  

 

Table 3

SegmentN. of IDsN. of IDs with productsN. of Product 1 at Level 2
A331
B321
C100

 

I hope you can help me out.

 

M.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hey I finally got it. Just forgot to add a filter in the end. So for measure 2 it's

Measure2 = 
VAR __filter = FILTER(Table2, Table2[Level] <> BLANK())
RETURN
CALCULATE(DISTINCTCOUNT(Table2[ID]),RELATEDTABLE(Table1),__filter)

View solution in original post

3 REPLIES 3
JW_van_Holst
Resolver IV
Resolver IV

First of all you have to unpivot Table2 in powerquery and set a relationship between Table1 (one side) and Table2 (many side). The measures below will give you the following results.

Picture2.png

Measure1 = COUNTROWS(Table1)
Measure2 = 
VAR __filter = FILTER(Table2, Table2[Level] <> BLANK())
RETURN
CALCULATE(DISTINCTCOUNT(Table2[ID]),__filter)
Measure3 = 
VAR __filter = FILTER(Table2, Table2[Product] = "Product 1" && Table2[Level] = "Level 2")
RETURN
CALCULATE(DISTINCTCOUNT(Table2[ID]),__filter)
Anonymous
Not applicable

Hey I finally got it. Just forgot to add a filter in the end. So for measure 2 it's

Measure2 = 
VAR __filter = FILTER(Table2, Table2[Level] <> BLANK())
RETURN
CALCULATE(DISTINCTCOUNT(Table2[ID]),RELATEDTABLE(Table1),__filter)
Anonymous
Not applicable

Thanks for the quick reply.

I followed everything as instructed but I'm getting only the total for measures 1 and 2. How do I relate those to my segments ?

Is it the one to many relationship ? If i understand how it works, the relationship's only for the ID column.

Again thanks so much.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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