Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
RockyR
New Member

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.

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

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:

vjianbolimsft_0-1673248918029.png

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:

vjianbolimsft_1-1673249202311.png

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.

View solution in original post

3 REPLIES 3
v-jianboli-msft
Community Support
Community Support

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:

vjianbolimsft_0-1673248918029.png

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:

vjianbolimsft_1-1673249202311.png

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.

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

Ashish_Mathur
Super User
Super User

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.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.