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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Filter master table based on a detail table

Hi, 

 

I'll illustrate my issue with dumb data. 

I'm looking for a DAX code to find the number of people who have both let's say apple and strawberries. 

 

2019-09-16 14_50_25-Book1 - Excel.png

 

I tried something like but it doesn't work 😃 

test = 
CALCULATE(
    COUNT(People[People]),
    INTERSECT(
            CALCULATETABLE(
                People,
                FILTER(
                    RELATEDTABLE(Belongings),
                    'Belongings'[Fruit]=1
                )
            ),
            CALCULATETABLE(
                People,
                FILTER(
                    RELATEDTABLE(Belongings),
                    'Belongings'[Fruit]=2
                )
            )
        )
)

Any help is more than welcome, 

 

Thanks

 

 

 

 

1 REPLY 1
AlB
Super User
Super User

Hi @Anonymous 

This depends on what you relationships look like but you could try this, where Table3 is the rightmost table you show:

1. Place Table3[Fruit] in a slicer and select apple and strawberries 

2. Create this measure and place it in a card visual:

Measure =
VAR NumFruits_ =
    COUNTROWS ( DISTINCT ( Table3[Fruit] ) )
RETURN
    COUNTROWS (
        FILTER (
            DISTINCT ( Table3[People] ),
            CALCULATE ( COUNT ( Table3[Fruit] ) ) = NumFruits_
        )
    )

On  a different note, please always show your sample data in text-tabular format in addition to (or instead of) the screen captures. A screen cap doesn't allow people to readily copy the data and run a quick test and thus decreases the likelihood of your question being answered. Just use 'Copy table' in Power BI and paste it here. Or, ideally, share the pbix (beware of confidential data).

 

Please mark the question solved when done and consider giving kudos if posts are helpful.

Cheers  Datanaut

  

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.