Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to create a measure which is a count of all records with a certain flag?

I am trying to get create a measure which is a count of all records where flag1="yes". I am using this formula:

 

count1 = calculate(countrows('table1'),filter(all('table1'[uniqueID]),'table1'[flag1]="yes" )

 

I am getting this error:

 

"A single value for column 'flag1' in table 'program' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result."

 

Why is this? Is there another way to accomplish this?

 

 

1 ACCEPTED SOLUTION
KHorseman
Community Champion
Community Champion

When you specify a column in an ALL() statement, it returns a table with that single column. The second column you refer to does not exist in that table. Your formula should be this:

 

CALCULATE(
	COUNTROWS('table1'),
	FILTER(
		ALL('table1'),
		'table1'[flag1] = "yes"
	)
)

 

Unless you were trying to use all('table1'[uniqueID]) to force the countrows to count each unique ID only once in a table that otherwise has duplicates. In that case you would want to do:

 

CALCULATE(
	DISTINCTCOUNT('table1'[uniqueID]),
	FILTER(
		ALL('table1'),
		'table1'[flag1] = "yes"
	)
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

2 REPLIES 2
KHorseman
Community Champion
Community Champion

When you specify a column in an ALL() statement, it returns a table with that single column. The second column you refer to does not exist in that table. Your formula should be this:

 

CALCULATE(
	COUNTROWS('table1'),
	FILTER(
		ALL('table1'),
		'table1'[flag1] = "yes"
	)
)

 

Unless you were trying to use all('table1'[uniqueID]) to force the countrows to count each unique ID only once in a table that otherwise has duplicates. In that case you would want to do:

 

CALCULATE(
	DISTINCTCOUNT('table1'[uniqueID]),
	FILTER(
		ALL('table1'),
		'table1'[flag1] = "yes"
	)
)




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

It works, thanks!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.