powerbidaxpowerbi-datasource

Count occurrences in Dax


I have the following table:

enter image description here

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

enter image description here

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.


Solution

  • 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.