Forum Discussion

seba's avatar
seba
Helper II
2 years ago
Solved

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!

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    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] )
        )

     

     

    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.

4 Replies