Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

DAX Count Filtering where a column contains text from another Table's Column

Hello I need to create a meassure that counts the items in a column filtering if the column contains a text from another table's column, I'll explain.

 

Table1:

IDProduct
1Apple, Banana, Orange
2Apple
4Banana
5Orange
6Banana, Orange
7Apple, Grape
8Grape
9Banana, Orange, Grape
10Orange, Grape


Table2: (Fruits Catalog)

Fruits
Apple
Banana
Orange
Grape

 

What I need is for each Table2[Fruits] count the Table1[ID] when Table1[Product] contains Table2[Fruits].

Expected outcome:

Apple3
Banana4
Orange5
Grape4

 

Hope you can help me, I have tried with the contains and containsstring with no posisitve results.

 

Thank you

6 Replies

  • AlB's avatar
    AlB
    Icon for Community Champion rankCommunity Champion

    Hi Anonymous 

    Try this:

    1. Place Table2[Fruit] in the rows of a matrix visual

    2. Create this measure and palce it in the visual

    Measure =
    COUNTROWS (
        FILTER (
            Table1;
            CONTAINSSTRING ( Table1[Product]; SELECTEDVALUE ( Table2[Fruits] ) )
        )
    )
    

     

    Please mark the question solved when we get to the solution and consider kudoing if posts are helpful.

    Cheers  Datanaut

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello AlB  I tried as you instructed but it is only showing the individual values, so it is not counting the fields where I have mixed fruits (cases..1, 6, 7, 9,10)

       

      the output is showing:

      Apple1
      Banana1
      Orange1
      Grape1

       

       

       

       

      • AlB's avatar
        AlB
        Icon for Community Champion rankCommunity Champion

         

        You sure you're doing it as described? I get exactly the results you show in your first post