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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
pry76092
Helper I
Helper I

Count number of one's and zero's for each product

Hi,

 

I have a table which contains colums: date, store_id, product_id, transaction_count and sales. if the transaction_count is greater than 0 then sales is 1 else its 0. So, now I want a measure which can help me to find number of one's and zero's for each product sold in each store.

Also, I want to know is it possible to get count of zero's as 1 if there is no sales mentioned for a particular date. So, in the below table we can see count of zero is 2 for store 21 and product no 42A5 because it has no sales on 12-05-2021 and 14-05-2021(but it has no record).

                                                                                                                      

Storeid   product_no      date        sale            transaction_count

 Measure

count of zero

     Measure 

count of one's

2142A511-05-2021   13         2          3
2242A511-05-2021   17         0          1
2142A512-05-2021   00         2          3
2342A511-05-2021   00         1          0
2342A611-05-2021   15         0          2
23 42A612-05-2021   16         0          2
2142A513-05-2021   12         1           2
2142A515-05-2021   15         2           3

 

 

Thank you

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @pry76092,

Did these zero records really exist in your tables? If they include in your table, you can try to use the following measure formula to calculate the two counts based on store and product:

zero count =
CALCULATE (
    COUNTROWS ( VALUE ( Table[date] ) ),
    FILTER ( ALLSELECTED ( Table ), Table[sales] = 0 ),
    VALUES ( Table[store_id] ),
    VALUES ( Table[product no] )
)

Not zero count =
CALCULATE (
    COUNTROWS ( VALUE ( Table[date] ) ),
    FILTER ( ALLSELECTED ( Table ), Table[sales] <> 0 ),
    VALUES ( Table[store_id] ),
    VALUES ( Table[product no] )
)

If not, it means you need to calculate the missed records based on current records instead count rows with filters to calculate zero records.

For this scenario, can you please share some dummy data that keep the raw data structure? They will help us clarify your data structure to test the coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@pry76092 , with help from a date table, joined to sales

 

M1 = sum(Table[sales]) +0

 

measure for sale =0 and > 0

 

countx(filter(summarize(Table, Table[Store], 'date'[Date], "_1", [M1]), [_1] =0 ), [Store])

 

 

countx(filter(summarize(Table, Table[Store], 'date'[Date], "_1", [M1]), [_1] >0 ), [Store])

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi,

 

Thanks for your solution but its not working as per requirement.

Its simplying puting 1's wherever the sale is 0 and 1 but its not adding them up to tell count of zero's and one's.

 

So, i tried other calculation which is returning correct information for count of one's but for count of zero's its not condsidering the date when there is no record of sales. example below

 

The meaure which I'm using is:

 

count of zero's= 

var _product=SELECTEDVALUE(TABLE[product no])

var _store=SELECTEDVALUE(TABLE[store_id])

return

CALCULATE(COUNTROWS(TABLE),ALL(TABLE),TABLE[sales]=0,TABLE(store_id)=_store,TABLE[product no]= _product)+0

 

 

count of one's= 

var _product=SELECTEDVALUE(TABLE[product no])

var _store=SELECTEDVALUE(TABLE[store_id])

return

CALCULATE(COUNTROWS(TABLE),ALL(TABLE),TABLE[sales]=1,TABLE(store_id)=_store,TABLE[product no]= _product)+0

Anonymous
Not applicable

HI @pry76092,

Did these zero records really exist in your tables? If they include in your table, you can try to use the following measure formula to calculate the two counts based on store and product:

zero count =
CALCULATE (
    COUNTROWS ( VALUE ( Table[date] ) ),
    FILTER ( ALLSELECTED ( Table ), Table[sales] = 0 ),
    VALUES ( Table[store_id] ),
    VALUES ( Table[product no] )
)

Not zero count =
CALCULATE (
    COUNTROWS ( VALUE ( Table[date] ) ),
    FILTER ( ALLSELECTED ( Table ), Table[sales] <> 0 ),
    VALUES ( Table[store_id] ),
    VALUES ( Table[product no] )
)

If not, it means you need to calculate the missed records based on current records instead count rows with filters to calculate zero records.

For this scenario, can you please share some dummy data that keep the raw data structure? They will help us clarify your data structure to test the coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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