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

To count the number of occurrences in Power BI, you can use the Count function in the DAX language. This function allows you to specify a column or expression to count, and will return the total number of rows that meet the specified criteria. You can also use filters and conditions in the Count function to further refine your count. This can be useful for analyzing data and determining the frequency of certain values or events within a dataset. Additionally, Power BI also offers visualizations such as bar charts or tables that automatically display the count of values in a given column, making it easier to visualize and understand the data.


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