Forum Discussion

RockyR's avatar
RockyR
New Member
3 years ago
Solved

Multiple FIlter CountRows of another table

Hello,

 

I am struggling to get a result for COUNTROWS based on multiple criteria.

I have a table called "QuestionRef". Im trying to count the rows in another table called "LineAudit". The rows need to match [Cell] and [QID] from the QuestionRef table.

 

QuestionRef

CellQNumQID

A

1

1
A22
B11
B23

 

LineAudit

CellQIDDateStatus

A

1

1/1/23

False

A21/1/23False
A11/2/23False
A21/2/23True
A11/3/23False
B11/3/23False
B31/3/23True
B11/3/23True
A21/3/23False

 

Desired Result

CellQNumQIDFalse Count

A

1

13
A222
B111
B230

 

I tried

 

False Count = 
CALCULATE(
    COUNTROWS(LineAudit),
        FILTER(LineAudit,LineAudit[Status]=FALSE()),
        FILTER(LineAudit,LineAudit[Cell] = QuestionRef[Cell]),
        FILTER(LineAudit,LineAudit[QID] = QuestionRef[QID] )
)

 

 

But I keep getting the error

 

A single value for column 'Cell' in table 'QuestionRef' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

 

Any help would be very appreciated.

  • Hi RockyR ,

     

    It seems that your DAX Code is used in a measure? If you need a measure, please try:

     

    Measure =
    CALCULATE (
        COUNTROWS ( LineAudit ),
        FILTER (
            'LineAudit',
            [Status] = FALSE ()
                && 'LineAudit'[Cell] = MAX ( 'QuestionRef'[Cell] )
                && 'LineAudit'[QID] = MAX ( 'QuestionRef'[QID] )
        )
    ) + 0
    

     

    Output:

    Your DAX code can be used in the calculation column:

     

    False Count = 
    CALCULATE(
        COUNTROWS(LineAudit),
            FILTER(LineAudit,LineAudit[Status]=FALSE()),
            FILTER(LineAudit,LineAudit[Cell] = QuestionRef[Cell]),
            FILTER(LineAudit,LineAudit[QID] = QuestionRef[QID] )
    )+0

     

    Note: Whenever there are no rows to aggregate, the function COUNTROWS() returns a blank. Thus you need +0

    Output:

    Best Regards,

    Jianbo Li

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

3 Replies

  • Hi RockyR ,

     

    It seems that your DAX Code is used in a measure? If you need a measure, please try:

     

    Measure =
    CALCULATE (
        COUNTROWS ( LineAudit ),
        FILTER (
            'LineAudit',
            [Status] = FALSE ()
                && 'LineAudit'[Cell] = MAX ( 'QuestionRef'[Cell] )
                && 'LineAudit'[QID] = MAX ( 'QuestionRef'[QID] )
        )
    ) + 0
    

     

    Output:

    Your DAX code can be used in the calculation column:

     

    False Count = 
    CALCULATE(
        COUNTROWS(LineAudit),
            FILTER(LineAudit,LineAudit[Status]=FALSE()),
            FILTER(LineAudit,LineAudit[Cell] = QuestionRef[Cell]),
            FILTER(LineAudit,LineAudit[QID] = QuestionRef[QID] )
    )+0

     

    Note: Whenever there are no rows to aggregate, the function COUNTROWS() returns a blank. Thus you need +0

    Output:

    Best Regards,

    Jianbo Li

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

    • RockyR's avatar
      RockyR
      New Member

      Worked great. Thank you so much! I also appreciated the explanation.

  • Hi,

    In the first table, write this calculated column formula

    Count = calculate(countrows(Lineaudit),filter(lineaudit,lineaudit[Cell]=earlier(lineaudit[Cell])&&lineaudit[QID]=earlier(lineaudit[QID])))

    Hope this helps.