This DAX expression for Count the number of occurrences of each country in a table using Power BI.
Count_Occurrences = COUNTROWS(FILTER('TABLE_NAME', 'TABLE_NAME'[COLUMN_NAME] = EARLIER('TABLE_NAME'[COLUMN_NAME])))
counts the number of occurrences of each country in the SELECTED table.
The COUNTROWS function counts the number of rows in a table.
The FILTER function filters a table based on a specified condition.
The EARLIER function returns the value of an expression that was evaluated in a previous context.
In this case, the FILTER function is filtering the table to only include rows where the Country column is equal to the current value of the Country column.
The EARLIER function is ensuring that the Country column is evaluated in the context of the current row.
Therefore, the expression will return the number of times that the current country appears in the table.
- The expression can be used in a variety of ways. For example, it could be used to create a report that shows the number of each country. It could also be used to create a measure that calculates the average number per country.