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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

COUNTROWS FILTER - Multiple Values

Hello, 

 

I have a column that has a number of 1's and 0's and I want to count how many 1's there are and 0's there are as they are base don a different column. 

 

I have tried to use the below measure but for some reason it doesn't work... please assist:

 

Measure = CALCULATE(
                        COUNTROWS(Table_query),
                        FILTER(Table_query, Table_query[Recharge Decision] = "1"),
                        FILTER(Table_query,Table_query[Recharge Decision] ="0"))

 

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

Hi @Anonymous ,

 

You need to split your measure into 2,1 is for calculating the number of 1's and the other is for the number of  0's:

If the data of the column is a text type,using:

 

Measure for 1 = CALCULATE(
                        COUNTROWS(Table_query),
                        FILTER(Table_query, Table_query[Recharge Decision] = "1")
Measure for 0= CALCULATE(
                        COUNTROWS(Table_query),
                        FILTER(Table_query, Table_query[Recharge Decision] ="0"),

 

If the data of the column is a whole number type,using:

 

Measure for 1 = CALCULATE(
                        COUNTROWS(Table_query),
                        FILTER(Table_query, Table_query[Recharge Decision] = 1)
Measure for 1 = CALCULATE(
                        COUNTROWS(Table_query),
                        FILTER(Table_query, Table_query[Recharge Decision] = 0)

 

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

 

View solution in original post

3 REPLIES 3
Justas4478
Post Patron
Post Patron

@amitchandak Hi I am trying to use these measures to calculate rows for my stock.
But it is bringing back not what I expect.

Count store stock = CALCULATE(COUNTROWS('Store Stock'),FILTER('Store Stock','Store Stock'[Store Stock Qty] = 0))

I know that total amount of row are 4572, but measure brings back only 4204.

Ideally I would like to avoid using filter inside measure so that I could use visual filter so used could filter on any value.

Justas4478_0-1699438675574.png 
I have other measure that, but it breaks when I add stores to the table.

Products stock at all stores =
VAR summarybyproduct =
ADDCOLUMNS(
    VALUES('Product'[SKU Number]),
    "Total stock",
   CALCULATE('Store Stock'[Store Stock Qty])
    )

VAR productswithzero =
FILTER(summarybyproduct,[Total stock])
RETURN
COUNTROWS(productswithzero)



I attached sample file if it helps
https://we.tl/t-LVpPk1HQoq 

 

v-kelly-msft
Community Support
Community Support

Hi @Anonymous ,

 

You need to split your measure into 2,1 is for calculating the number of 1's and the other is for the number of  0's:

If the data of the column is a text type,using:

 

Measure for 1 = CALCULATE(
                        COUNTROWS(Table_query),
                        FILTER(Table_query, Table_query[Recharge Decision] = "1")
Measure for 0= CALCULATE(
                        COUNTROWS(Table_query),
                        FILTER(Table_query, Table_query[Recharge Decision] ="0"),

 

If the data of the column is a whole number type,using:

 

Measure for 1 = CALCULATE(
                        COUNTROWS(Table_query),
                        FILTER(Table_query, Table_query[Recharge Decision] = 1)
Measure for 1 = CALCULATE(
                        COUNTROWS(Table_query),
                        FILTER(Table_query, Table_query[Recharge Decision] = 0)

 

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

 

amitchandak
Super User
Super User

If there other values then 1 and 0 then

Measure = CALCULATE(
COUNTROWS(Table_query),
FILTER(Table_query, Table_query[Recharge Decision] = "1" || Table_query[Recharge Decision] ="0"))

 

Other wise create 2 measures

Measure1 = CALCULATE(
COUNTROWS(Table_query),
FILTER(Table_query, Table_query[Recharge Decision] = "1" ))

 

Measure2 = CALCULATE(
COUNTROWS(Table_query),
FILTER(Table_query,  Table_query[Recharge Decision] ="0"))

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.