Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

How to filter properly?

Edited per Greg_Deckler suggestion. Thank you Hello, I have a report that I am attempting to provide the users with two seamlingly simple a simple [Count] and [Modified Count] measues. The [Count...
  • Greg_Deckler's avatar
    Greg_Deckler
    6 years ago

    Anonymous - Assuming the answer to the previous question is "Yes" the modified code is below. Essentially you had it correct except that you cannot recalculate a variable, which is what you were trying to do. This is why you were getting the incorrect result.

     

    ModifiedCount = 
        VAR Metric = SUM('f_primary'[Count])
        VAR HasOneExpression = 
            OR ( 
                HASONEVALUE ( 'f_primary'[Field.1] ), 
                HASONEVALUE ( 'f_primary'[Field.2] ) 
            )
        VAR CalcHasOneFilter = 
            CALCULATE ( 
                 SUM('f_primary'[Count]), 
                ALLEXCEPT ( 'f_primary', 'f_primary'[Field.1], 'f_primary'[Field.2], 'DateTbl'[Date] )
            ) 
        VAR CalcAll = CALCULATE ( SUM('f_primary'[Count]), ALLEXCEPT(f_primary, DateTbl[Date]))
    RETURN
        IF ( HasOneExpression, CalcHasOneFilter, CalcAll )