Forum Discussion

a11smiles's avatar
a11smiles
New Member
4 years ago
Solved

Joining and Filtering

Let's say I have three tables:

 

Food Table (Coming from OData service):

 

IDFood
1Apple
2Orange
3Lettuce
4Carrot
5Grape

 

I also have two reference tables:

 

Fruits

ID
1
2
5

 

 

Vegetables

ID
3
4

 

 

 

Problem/Goal:

 

On my report page, I have a table of all the food.  I'd like to create a slicer that allows me to toggle showing only fruit or vegetables or both. This is a contrived set of data, but the real data set may have items that fall into both subcategories (e.g. with a table with colors, if one chose "orange," then both orange and carrot would be visible).

 

I could fill my table with bits such as:

 

IDFoodFruitVegetableOrangeRedGreen
1Apple1  1 
2Orange1 1  
3Lettuce 1  1
4Carrot 11  
5Grape1   1

 

So, how do I create a "Slicer" with various options such as, fruit, vegetable, orange, red, and green to filter? Or, am I going about this the wrong way?

 

Thanks!

  • Hi a11smiles ,

     

    1 Create a table for slicer contains fruit,vegetable,orange, red and green.

    2 Create a matrix table then ID, Food in the rows and options in the columns.

    3 Create a measure like this:

    Measure =
    VAR _1 =
        SELECTEDVALUE ( 'Food Table'[ID] )
    RETURN
        SWITCH (
            SELECTEDVALUE ( Slicer[options] ),
            "fruit", IF ( _1 IN VALUES ( Fruits[ID] ), 1 ),
            "vegetable", IF ( _1 IN VALUES ( Vegetables[ID] ), 1 ),
            "red", IF ( _1 IN VALUES ( Red[ID] ), 1 ),
            "orange", IF ( _1 IN VALUES ( Orange[ID] ), 1 ),
            "green", IF ( _1 IN VALUES ( Green[ID] ), 1 )
        )
    

     

    Result:

    Pbix in the end you can refer.

    Best Regards

    Community Support Team _ chenwu zhu

     

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

1 Reply

  • v-chenwuz-msft's avatar
    v-chenwuz-msft
    Community Support

    Hi a11smiles ,

     

    1 Create a table for slicer contains fruit,vegetable,orange, red and green.

    2 Create a matrix table then ID, Food in the rows and options in the columns.

    3 Create a measure like this:

    Measure =
    VAR _1 =
        SELECTEDVALUE ( 'Food Table'[ID] )
    RETURN
        SWITCH (
            SELECTEDVALUE ( Slicer[options] ),
            "fruit", IF ( _1 IN VALUES ( Fruits[ID] ), 1 ),
            "vegetable", IF ( _1 IN VALUES ( Vegetables[ID] ), 1 ),
            "red", IF ( _1 IN VALUES ( Red[ID] ), 1 ),
            "orange", IF ( _1 IN VALUES ( Orange[ID] ), 1 ),
            "green", IF ( _1 IN VALUES ( Green[ID] ), 1 )
        )
    

     

    Result:

    Pbix in the end you can refer.

    Best Regards

    Community Support Team _ chenwu zhu

     

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