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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ezolezzi92
New Member

Counting by grouping

Hi all,

 

I'm trying to come up with a formula that counts & shows the departments for each of the following IDs:

IDDepartment
101290A
103458B
101290B

 

For example, I would like to show for 101290: 2 (A & B)

 

Could someone please guide me?
Thanks in advance.

2 REPLIES 2
Anonymous
Not applicable

[Departments] =
// HASONEFILTER makes sure that you have put
// a filter on ID and only one ID is visible
// in the current context. You can also use
// HASONEVALUE but this one only makes sure
// that one value of ID is visible in the current
// context, be it through an explicit filter
// or cross-filtering.
IF( HASONEFILTER( T[ID] ),

	var __depts = VALUES( T[Department] )
	var __deptCount = COUNTROWS( __depts )
	var __output =
		if( __deptCount > 0,
			__deptCount & " (" &
			& CONCATENATEX(
				__depts,
				T[Department],
				",",
				T[Department],
				ASC)
			& ")"
		)
	return
		__output
)

 

Best

D

harshnathani
Community Champion
Community Champion

Hi @ezolezzi92 ,

 

You can create 2 measures

 

Departments = CONCATENATEX(FILTER(ALL('Table'), 'Table'[ID] = MAX('Table'[ID])),'Table'[Department],",")

 

Count of ID = COUNT('Table'[ID])

 

 

1.jpg

 

 

 

Regards,

Harsh Nathani


Appreciate with a Kudos!! (Click the Thumbs Up Button)

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

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.