Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Dax Filter 2 tables

Hi,

 

I have 2 related table many to one

Table 1

Name     category

Category 1
BCategory 1
CCategory 2
Category 2
Category 2
Category 3
GCategory 4
HCategory 4
ICategory 5
JCategory 6
KCategory 7
LCategory 8
MCategory 9

 

Table 2

Name     Policy      Category 

WP Category 1
FixedCategory 1
 Category 1
WP Category 1
BFixedCategory 1
BFixedCategory 1
BFixedCategory 1
BFixedCategory 1
CFixedCategory 2
CFixedCategory 2
CFixedCategory 2
CFixedCategory 2
WP Category 2
FixedCategory 2
WP Category 2
WP Category 2
WP Category 2
FixedCategory 2
WP Category 2
WP Category 2
WP Category 3
FixedCategory 3
WP Category 3
WP Category 3
GFixedCategory 4
GFixedCategory 4
GFixedCategory 4
GFixedCategory 4
HFixedCategory 4
HWP Category 4
H Category 4
HWP Category 4
HADERCategory 4

 

 

I got the error message when I use this filter : 

 

 A function 'FILTER' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

 

measure = 

var  _Conform = Calculate(Distinctcount(Table1[Name], Table1[Category] IN {"Category 1", "Category 2", "Category 3", "Category 4"} && Filter(Table2, Table2[Policy] <> "WP"))

var  _Total = Calculate(Distinctcount(Table1[Name], Table1[Category] IN {"Category 1", "Category 2", "Category 3", "Category 4"} )
Return Rounddown(_Conform/_Total,2)
 It works If I remove Filter(Table2, Table2[Policy] <> "WP")

 

Could you please advide the solution?

Many thanks in advance.

 

  • lbendlin's avatar
    lbendlin
    2 years ago

    conform:  COUNTROWS ( FILTER ( a, [has WP] = 0 ) )

    non-conform: COUNTROWS ( FILTER ( a, [has WP] > 0 ) )

4 Replies

  • MEASURE =
    VAR a =
        ADDCOLUMNS (
            SUMMARIZE ( Table1, [Name] ),
            "has WP"CALCULATE ( COUNTROWS ( Table2 ), Table2[Policy] = "WP" )
        )
    RETURN
        ROUNDDOWN (
            DIVIDE ( COUNTROWS ( FILTER ( a, [has WP] = 0 ) )COUNTROWS ( a )0 ),
            2
        )

    • Anonymous's avatar
      Anonymous
      Not applicable

      lbendlin Hi, Many thanks for your quick reply. The measure works, I would like to sort out the list of Conform and No Conform, could you please advise the measure to count the number of Conform and Non Conform.

      If the same Name has FIXED and WP, this Name is not conformed. 

      Only the Name without any WP is Conform

       

      Thank you again. 

      Regards,

      Tg

      • lbendlin's avatar
        lbendlin
        Super User

        conform:  COUNTROWS ( FILTER ( a, [has WP] = 0 ) )

        non-conform: COUNTROWS ( FILTER ( a, [has WP] > 0 ) )