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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
bookhouseboy
Helper I
Helper I

IF not working right - filter out items with less than x entries

So I want to calculate my total sales, but I only want to do it for products that have more than one entry in my database. 

 

I tried to define my measure as 

MS_cond = IF(COUNT('products'[name]) > 1,
SUM('products'[items_per_day]),
"")

but it always goes into the ELSE part for every product, even though

items_count = COUNT('products'[name])

 on its own returns plenty of products with more than one entry. What am I doing wrong? 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

@bookhouseboy 

Can you give this a try?  It should build the list of product with > 1 count and return the amount for just those.

 

MS_Cond =
VAR _ProductsWithCount =
    ADDCOLUMNS (
        VALUES ( 'products'[name] ),
        "@Count", CALCULATE ( COUNT ( 'products'[name] ) )
    )
VAR _MultiProducts =
    FILTER ( _ProductsWithCount, [@Count] > 1 )
RETURN
    CALCULATE ( SUM ( 'products'[items_per_day] ), _MultiProducts )

 

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

@bookhouseboy 

Can you give this a try?  It should build the list of product with > 1 count and return the amount for just those.

 

MS_Cond =
VAR _ProductsWithCount =
    ADDCOLUMNS (
        VALUES ( 'products'[name] ),
        "@Count", CALCULATE ( COUNT ( 'products'[name] ) )
    )
VAR _MultiProducts =
    FILTER ( _ProductsWithCount, [@Count] > 1 )
RETURN
    CALCULATE ( SUM ( 'products'[items_per_day] ), _MultiProducts )

 

This works beautifully, thank you! I would never have thought of that by myself!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.