Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hi!
I cannot seem to figure out how to create a measure that would calculate the number of times a value appears in another column.
My tables and the measure result I would like:
Column1 - Column 2 - Measure (total 3)
1 4 0
2 5 0
3 5 0
4 1
5 2
6 0
7
Seems simple, but how to solve this in a measure?
Thanks in advance for any thoughts!
Solved! Go to Solution.
Hi @Anonymous
Unfortunately, I don't know what is the structure of your dataset, but it worked ok when applied to the sample you have provided.
All() - Removes all filters from a current filter context this allows the measure to count occurrences of 5 that are in different rows.
VAR x = VALUES( 'Table'[Column1] ) -- this part selects distinct value for column1 in each give row and all values for total RETURN CALCULATE( COUNTROWS( 'Table' ), -- count rows in a table in a filter context created by CALCULATE ALL(), - removes all filters TREATAS( x, 'Table'[Column2] ) -- filters table where column2 = column1 ) + 0
Thanx!
It works well on the row level, however the measure total does not give the sum on the row values. What is the logic for the measure total calculation?
Secondly, could you please tell me, why the ALL() is needed in there (why without it it does nnot work on the row level?
Thanks in advance!
Hi @Anonymous
Unfortunately, I don't know what is the structure of your dataset, but it worked ok when applied to the sample you have provided.
All() - Removes all filters from a current filter context this allows the measure to count occurrences of 5 that are in different rows.
VAR x = VALUES( 'Table'[Column1] ) -- this part selects distinct value for column1 in each give row and all values for total RETURN CALCULATE( COUNTROWS( 'Table' ), -- count rows in a table in a filter context created by CALCULATE ALL(), - removes all filters TREATAS( x, 'Table'[Column2] ) -- filters table where column2 = column1 ) + 0
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
72 | |
68 | |
53 | |
39 | |
33 |
User | Count |
---|---|
70 | |
63 | |
57 | |
49 | |
46 |