How can I count the number of occurrences in Power BI?

Counting the number of occurrences in Power BI refers to the process of determining the frequency of a specific data point or value within a dataset. This can be useful in analyzing data and identifying patterns or trends. In Power BI, this can be achieved using various functions and tools, such as the COUNT and COUNTROWS functions, as well as the visualizations and filters available. By accurately counting occurrences, users can gain valuable insights and make informed decisions based on their data.

Count Number of Occurrences in Power BI


You can use the following syntax in DAX to calculate the number of occurrences of each value in a column in Power BI:

occurrences = 
COUNTX(
    FILTER( 'my_data', EARLIER('my_data'[Team]) = 'my_data'[Team] ),
    'my_data'[Team]
)

This particular example counts the number of occurrences of each value in the team column of the table named my_data.

The following example shows how to use this syntax in practice.

Example: How to Count Number of Occurrences in Power BI

Suppose we have the following table in Power BI named my_data:

Suppose we would like to add a new column that contains the count of occurrences of each value in the team column.

To do so, click the New column icon:

Then type in the following formula into the formula bar:

occurrences = 
COUNTX(
    FILTER( 'my_data', EARLIER('my_data'[Team]) = 'my_data'[Team] ),
    'my_data'[Team]
)

This will create a new column named occurrences that contains the count of occurrences of each value in the team column:

Power BI count occurrences of each value in column

For example, we can see:

  • The team name Mavs occurs 4 times.
  • The team name Rockets occurs 2 times.
  • The team name Spurs occurs 3 times.

And so on.

Additional Resources

The following tutorials explain how to perform other common tasks in Power BI:

x