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
eiriksan
Frequent Visitor

Need help creating a measure

Hi,

 

I've been stuck trying to create a specific measure for days now and sorely need some help. Below is a simplified description of the problem:

 

I have two tables:

 

Table1:                          Table2:

Name                           Name      Category

a                                    a               1

b                                    b              1

b                                    c               2

c                                    d               2

c

c

d

 

The two tables are linked by the column "Name".

 

I'm trying to create a visual (e.g. a matrix) that diplays the distinct values in Table1[Name] along with the count of occurences in Table1[Name] of the names that belong to the same category. Something like this:

 

Name    Measure

a             3                 ("a" belongs to category "1" and there are 3 occurences of "a" and "b" in Table1[Name])

b             3                ("b" belongs to category "1" and there are 3 occurences of "a" and "b" in Table1[Name])

c             4                 ("c" belongs to category "2" and there are 4 occurences of "c" and "d" in Table1[Name])

d             4                ("d" belongs to category "2" and there are 4 occurences of "c" and "d" in Table1[Name])

 

What I need is a measure that responds in the way illustrated above. The measure must be dynamic and respond to other filters. Any help would be greatly appreciated!

 

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@eiriksan

 

You can use this MEASURE

 

Measure =
VAR mycategory =
    LOOKUPVALUE ( Table2[Category], Table2[Name], SELECTEDVALUE ( Table1[Name ] ) )
RETURN
    COUNTX (
        FILTER ( ALL ( Table1 ), RELATED ( Table2[Category] ) = mycategory ),
        1
    )

View solution in original post

3 REPLIES 3
Zubair_Muhammad
Community Champion
Community Champion

@eiriksan

 

You can use this MEASURE

 

Measure =
VAR mycategory =
    LOOKUPVALUE ( Table2[Category], Table2[Name], SELECTEDVALUE ( Table1[Name ] ) )
RETURN
    COUNTX (
        FILTER ( ALL ( Table1 ), RELATED ( Table2[Category] ) = mycategory ),
        1
    )

Thanks a lot! The first solution worked well and solved my problem. Much appreciated!

@eiriksan

 

Another way could be to add a calculated column in Table1 to get the category

 

 

Category = RELATED(Table2[Category])

 

Then use this MEASURE

 

Measure 2 = VAR mycategory=selectedvalue(Table1[Category])
RETURN
CALCULATE(count(Table1[Name ]),Filter(all(Table1),Table1[Category]=mycategory))

Please see file attached

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors