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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
SimDam
Helper I
Helper I

Count group by with condition

Hi,

Considering the below table

 

OrderPeriod ItemTest
1007/1/2022 10
1007/1/2022 20
1007/1/2022 31
1008/1/2022 10
1008/1/2022 20
1008/1/2022 30
1009/1/2022 11
1009/1/2022 21
1009/1/2022 30
2007/1/2022 101
2007/1/2022 201
2008/1/2022 100
2008/1/2022 200

 

I need to count if I have at least one Item with Test =1 for each Period by Order.

The result should be:

 

OrderTest Count
1002
2001

 

For the Order 100, only for the period 7/1/2022 and 9/1/2022 I have at least one Item with Test=1 and for the Order 200, only the period 7/1/2022 has at least one Item with Test=1 (in this case both items are fulfulling the condition but anyhow I just need at least one to fulfill the condition to count that period in the final result).

How to write a measure for "Test Count"?

Thank you

1 ACCEPTED SOLUTION
FreemanZ
Community Champion
Community Champion

hi @SimDam 

try to write the measure like this:

TestCount = 
VAR _table = 
ADDCOLUMNS(
    VALUES(TableName[Period]),
    "Test",    
    CALCULATE(MAX(TableName[Test]))
)
RETURN
COUNTROWS(FILTER(_table, [Test]=1))

 

it worked like this:

FreemanZ_0-1673939045829.png

 

View solution in original post

3 REPLIES 3
FreemanZ
Community Champion
Community Champion

hi @SimDam 

try to write the measure like this:

TestCount = 
VAR _table = 
ADDCOLUMNS(
    VALUES(TableName[Period]),
    "Test",    
    CALCULATE(MAX(TableName[Test]))
)
RETURN
COUNTROWS(FILTER(_table, [Test]=1))

 

it worked like this:

FreemanZ_0-1673939045829.png

 

This is already working so I will go for it.

Thanks!

you may also write like this:

TestCount2 =
VAR _table =
CALCULATETABLE(
    TableName,
    TableName[Test]=1
)
VAR _table1 =
SUMMARIZE(
    _table,
    TableName[Period]
)
RETURN
COUNTROWS(_table1)

or 

TestCount3 =
VAR _table =
FILTER(
    TableName,
    TableName[Test]=1
)
VAR _table1 =
SUMMARIZE(
    _table,
    TableName[Period]
)
RETURN
COUNTROWS(_table1)

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.