Forum Discussion

JMHenriques's avatar
JMHenriques
Frequent Visitor
2 years ago
Solved

SUM and/or count depending on value

Hi all,   This is driving me nuts... Take the following data as an example:   Contract Product Amount 1001 Product 1 1 1001 Product 1 1 1001 Product 1 0 1001 Product 1 0 ...
  • jgeddes's avatar
    2 years ago

    Something like this might work for you...

    Measure = 
    var _sum =
    SUMX('Table', 'Table'[Amount])
    var _zeroRows = 
    COUNTROWS(FILTER('Table', 'Table'[Amount] = 0))
    var _oneRows =
    COUNTROWS(FILTER('Table', 'Table'[Amount] = 1))
    var _rowCount =
    COUNTROWS('Table')
    Return
    IF(
        _zeroRows + _oneRows = _rowCount,
        1,
        _sum
    )

    Using your example table the above measure returns