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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.