Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Slicing two tables

Hello, I’m relatively new to DAX and struggling with the following, so any help would be greatly appreciated. Apologies, if this has been asnwered already, but I couldn't find anything similar.

 

I’ve the following two tables.

TABLE1

CombinationIndex
abcdx
adcy
cbdy
bdy
acx

 

TABLE2

IDCount
a3
b3
c4
d4

 

Table2[Count] describes how often Table2[ID] appears in Table1[Combinations], specifically:

 

 

Count = CALCULATE(COUNTA(Table1[Combination]),FILTER(Table1, SEARCH(Table2[ID], Table1[Combination],,0)))

 

 

These table are linked through Table1[Combination] and Table2[Count].

 

I would like to filter through Table1[Index] and have Table2 automatically updated but so far I haven't managed to. For example, when selecting Tabl1[Index] = x, I would like:

 

IDCount
a2
b1
c1
d1

 

What am I missing? Thank you very much in advance!

  • Hi Anonymous ,

     

    You could try SELECTEDVALUE() function.

    Count=
    CALCULATE (
        COUNTA ( 'Table1'[Combination] ),
        FILTER (
            'Table1',
            SEARCH ( SELECTEDVALUE ( 'Table2'[ID] ), 'Table1'[Combination],, 0 )
        )
    )

    But I think the count of c should be 2 when you select x. 

     

6 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Well, if these are actually tables then what you are trying to do cannot be done because tables only update upon data load/refresh.

     

    You would need a measure.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Okay, good to know, thanks!

       

      However, when I tried to create a measure, I got a mistake becasue it can't find an aggregation for Table2[ID] since it's in text form.

      Does this make sense? Thanks again!

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion
        Generally you just wrap it with MAX or MIN depending on your preference. Doesn't matter what the aggregation is when it is filtered to one. Anonymous