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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
TomdB
Frequent Visitor

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'), 'AUDIT line'[Amnt] = EARLIER ( 'AUDIT line'[Amnt] ) && CALCULATE(COUNT('AUDIT line'[Amnt]), ALL('AUDIT line')) = 1)).

The problem here is that Power BI does not accept my input parameters for the EARLIER function and displays the message: "Parameter is not the correct type". The table and column do really exist and I checked for typos but that also does not seem to be the case. What am I doing wrong? I have studied examples and in those examples, the same kind of input parameters are inserted in the EARLIER function. Any help would be appreciated!
1 ACCEPTED SOLUTION
AlB
Super User
Super User

@TomdB 

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
    )
)

SU18_powerbi_badge

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.

 

View solution in original post

4 REPLIES 4
AlB
Super User
Super User

@TomdB 

or yet another, more elegant, option:

Unieke waarde V4 = 
COUNTROWS(    
    FILTER (
        ALL ( 'AUDIT line'[Amnt] ),
        CALCULATE (COUNT ( 'AUDIT line'[Amnt] )) = 1
    )
)

 

Unieke waarde V5 = 
SUMX (
        ALL ( 'AUDIT line'[Amnt] ),
        1*(CALCULATE (COUNT ( 'AUDIT line'[Amnt] )) = 1)
    )

SU18_powerbi_badge

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.

 

AlB
Super User
Super User

@TomdB 

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
    )
)

SU18_powerbi_badge

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.

 

AlB
Super User
Super User

Hi @TomdB 

If this is a measure, there is no previous/earlier row context in your code that EARLIER can refer to and thus fails.

I assume you are trying to calculate the number of values in the 'AUDIT line'[Amnt] column that appear only once in the table. If so:

 

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

 

SU18_powerbi_badge

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.

 

Greg_Deckler
Super User
Super User

@TomdB There's no row context for EARLIER to operate on that provides that column. You could do this instead:

    VAR __Amnt = MAX('AUDIT line'[Amnt])
    VAR __Result = 
    CALCULATE(
        DISTINCTCOUNT('AUDIT line'[Amnt]), 
        FILTER(
            ALL('AUDIT line'), 
            'AUDIT line'[Amnt] = __Amnt 
        )

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.

Top Solution Authors
Top Kudoed Authors