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
seba
Helper II
Helper II

Power BI Model Question

Hi! Hope all is well! Here is the challenge I am facing and looking for help with – I do have the below reference table with people names and fruits they would like to get. Each person is “satisfied” only when they get all the fruits they are looking for (for some it is one, for some it is multiple). I am looking to understand what code do I need to use in order to be able to answer the following questions (I believe they are all the same question just worded differently):

  • How many people would be satisfied if I get:
    • Just Apples
    • Apples + Pears
    • Just Oranges etc.
    • Most critical question - all possible combinations (this can be accomplished using a filter or so), it would be great to automate it as much as possible instead of clicking different filter combinations and "writing down" the results
  • What is a fruit mix which would satisfy the most people?
  • Would love to be able to show how the number of satisfied people could grow as I add fruits to the mix

Any help would be greatly appreciated! Thank you!

 

Names&Fruits.png

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @seba ,

I understand your requirement and I think you can change your table and use this DAX code. Here is a similar example.

Measure 3 = 
VAR _Slicer = VALUES('T2'[Car Name])
VAR _vtable = ADDCOLUMNS(GENERATE('T1',_Slicer),"AAA",IF(FIND('T2'[Car Name],'T1'[Name],,BLANK())<>BLANK(),'T2'[Car Name]))
VAR _vtable2 = SUMMARIZE (
        _vtable,
        [Name],
        "BBB",
            IF (
                LEN ( CONCATENATEX ( _Slicer, 'T2'[Car Name] ) )
                    = LEN ( CONCATENATEX ( FILTER ( _vtable, 'T1'[Name] = EARLIER ( 'T1'[Name] ) ), [AAA] ) ),
                CONCATENATEX ( FILTER ( _vtable, 'T1'[Name] = EARLIER ( 'T1'[Name] ) ), [AAA] )
            )
    )
RETURN
IF (
        CONCATENATEX ( FILTER ( _vtable2, [Name] = 'T1'[Name] ), [BBB] )
            <> BLANK (),
        CONCATENATEX ( FILTER ( _vtable2, [Name] = 'T1'[Name] ), [BBB] )
    )

vyilongmsft_0-1719390911695.png

vyilongmsft_1-1719390992795.png

 

 

Best Regards

Yilong Zhou

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

4 REPLIES 4
Anonymous
Not applicable

Hi @seba ,

I create a table as you mentioned.

vyilongmsft_0-1718590808740.png

Then I create two measures and here is the DAX code.

Satisfied People = 
VAR SelectedFruits = ALLSELECTED('Table'[Fruit])
VAR SatisfiedCount = 
    CALCULATE(
        DISTINCTCOUNT('Table'[Name]),
        FILTER(
            SUMMARIZE(
                'Table',
                'Table'[Name],
                "AllFruits", CALCULATETABLE(VALUES('Table'[Fruit]), ALL('Table'))
            ),
            ISEMPTY(EXCEPT(VALUES('Table'[Fruit]), SelectedFruits))
        )
    )
RETURN
SatisfiedCount
Best Fruit Mix = 
VAR FruitCombinations = SUMMARIZE('Table', [Fruit])
VAR BestMix = 
    TOPN(
        1,
        FruitCombinations,
        [Satisfied People],
        DESC
    )
RETURN
BestMix

vyilongmsft_1-1718591294755.pngvyilongmsft_2-1718591323544.png

 

 

 

Best Regards

Yilong Zhou

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

Thank you for looking into this @Anonymous ! I think we are close, but not there yet.

 

Using your code, when I filter for Orange, I see all people (Alice, Seb, Zach) who want orange as one of their fruits to be satisfied. However, I expect to see Zach only. The reason is only Zach wants only organges to be satisfied, he does not want any other fruits. Alice and Seb need more fruits to be satisfied (different fruits each one of them). A person is satisfied only when they get all the fruits they want (have listed on the spreadsheet).

 

That is how I would like to see the data - be able to manipulate, or better have Power BI tell me, fruits and see what mix of fruits will give me the highest number of satisfied people, again remebering that people are satisified only when they get all the fruits they want. Hope this clarifies my question.

 

Once again, thank you for help.

Anonymous
Not applicable

Hi @seba ,

I understand your requirement and I think you can change your table and use this DAX code. Here is a similar example.

Measure 3 = 
VAR _Slicer = VALUES('T2'[Car Name])
VAR _vtable = ADDCOLUMNS(GENERATE('T1',_Slicer),"AAA",IF(FIND('T2'[Car Name],'T1'[Name],,BLANK())<>BLANK(),'T2'[Car Name]))
VAR _vtable2 = SUMMARIZE (
        _vtable,
        [Name],
        "BBB",
            IF (
                LEN ( CONCATENATEX ( _Slicer, 'T2'[Car Name] ) )
                    = LEN ( CONCATENATEX ( FILTER ( _vtable, 'T1'[Name] = EARLIER ( 'T1'[Name] ) ), [AAA] ) ),
                CONCATENATEX ( FILTER ( _vtable, 'T1'[Name] = EARLIER ( 'T1'[Name] ) ), [AAA] )
            )
    )
RETURN
IF (
        CONCATENATEX ( FILTER ( _vtable2, [Name] = 'T1'[Name] ), [BBB] )
            <> BLANK (),
        CONCATENATEX ( FILTER ( _vtable2, [Name] = 'T1'[Name] ), [BBB] )
    )

vyilongmsft_0-1719390911695.png

vyilongmsft_1-1719390992795.png

 

 

Best Regards

Yilong Zhou

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

Ritaf1983
Super User
Super User

Hi @seba 
It sounds like you are talking about basket analysis.

Please refer to the linked guides:

https://www.daxpatterns.com/basket-analysis/

https://blog.finance-bi.com/power-bi-basket-analysis/

https://medium.com/@jackyogingo/market-basket-analysis-dashboard-in-power-bi-daf391fe7cb8#id_token=e...

and video:

https://www.youtube.com/watch?v=yzDGvZEtYdQ

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

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

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