Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

EARLIER Function not working

Dear Power BI heroes,   I have a question regarding the EARLIER function. I have the following DAX query: Unieke waarde =     CALCULATE(DISTINCTCOUNT('AUDIT line'[Amnt]), FILTER(ALL('AUDIT line'...
  • AlB's avatar
    3 years ago

    Anonymous 

    An alternative version that uses EARLIER as you initially intended:

    Unieke waarde V3 = 
    CALCULATE (
        DISTINCTCOUNT ( 'AUDIT line'[Amnt] ),
        FILTER (
            ALL ( 'AUDIT line' ),
            CALCULATE (COUNT ( 'AUDIT line'[Amnt] ), 'AUDIT line'[Amnt] = EARLIER('AUDIT line'[Amnt] ), ALL('AUDIT line')) = 1
        )
    )

     or the same using variables instead of EARLIER, which is recommended nowadays:

    Unieke waarde V3B = 
    CALCULATE (
        DISTINCTCOUNT ( 'AUDIT line'[Amnt] ),
        FILTER (
            ALL ( 'AUDIT line' ),
            VAR amnt_ = 'AUDIT line'[Amnt]
            RETURN
            CALCULATE (COUNT ( 'AUDIT line'[Amnt] ), 'AUDIT line'[Amnt] = amnt_ , ALL('AUDIT line')) = 1
        )
    )

    Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

    Contact me privately for support with any larger-scale BI needs, tutoring, etc.