-->

Count occurrences in Dax

2019-07-29 11:52发布

问题:

I have the following table:

Now, I want to apply some dax instructions to that table, and display this data in a chart:

Or in other words, I if it is the first time that the Country's name appears, it must show 1 and 2 for the second time.

回答1:

Try this for creating a calculated column called Occurrences:

Occurrences =
CALCULATE (
    COUNT ( [Pais] ),
    FILTER (
        'Table',
        [Index] <= EARLIER ( 'Table'[Index] )
            && [Pais] = EARLIER ( 'Table'[Pais] )
    )
)

Index must be an incremental key in each row.

Let me know if this helps.