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
JS
Helper II
Helper II

Concatenatex challenges

Hello!

 

I have a set of small data below:

 

ClientProduct/ServiceCountry
Client AProduct 1Malaysia
Client AProduct 2China
Client AProduct 2Hong Kong
Client AProduct 2India
Client AProduct 2Indonesia
Client AProduct 2Malaysia
Client AProduct 2Philippines
Client AProduct 2Singapore
Client AProduct 2Taiwan
Client AProduct 2Thailand
Client AProduct 2Vietnam
Client AProduct 3Hong Kong
Client AProduct 10China
Client BProduct 11Hong Kong
Client BProduct 1Hong Kong
Client BProduct 4Hong Kong
Client BProduct 4Malaysia
Client BProduct 4Singapore

 

and i would like to have a desired output like this:

ClientProduct & Country
Client AProduct 1 (Malaysia), Product 2 (China, Hong Kong, Malaysia, India, Indonesia, Malaysia, Philippines, Singapore, Taiwan, Thailand, Vietnam), Product 3 (Hong Kong)
Client B

Product 11 (Hong Kong), Product 1 (Hong Kong), Product 4 (Hong Kong, Malaysia, Singapore)

 

I am able to use concatenatex and values to obtain unique list of product or country values. however I am not able to get around my head in summarizing it in the desired output. 

 

What would be the DAX approach to have this output. Appreciate the guidance and help! 

 

Cheers

JS

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

You can create a calculated column like

Product & country = 
	VAR  Products = CALCULATETABLE(
		VALUES( 'Table'[Product/Service] ), ALLEXCEPT( 'Table', 'Table'[Client] )
		
	)
	VAR  Result = CONCATENATEX( Products,
		VAR  CurrentProduct = 'Table'[Product/Service]
		VAR  Countries = CALCULATETABLE( VALUES( 'Table'[Country] ), ALLEXCEPT( 'Table', 'Table'[Product/Service], 'Table'[Client] ) )
		VAR  CountryString = CONCATENATEX( Countries, 'Table'[Country], ", " )
		RETURN  CurrentProduct & " ( " & CountryString & " ) ",
		", "
	)
	RETURN  Result

View solution in original post

3 REPLIES 3
johnt75
Super User
Super User

You can create a calculated column like

Product & country = 
	VAR  Products = CALCULATETABLE(
		VALUES( 'Table'[Product/Service] ), ALLEXCEPT( 'Table', 'Table'[Client] )
		
	)
	VAR  Result = CONCATENATEX( Products,
		VAR  CurrentProduct = 'Table'[Product/Service]
		VAR  Countries = CALCULATETABLE( VALUES( 'Table'[Country] ), ALLEXCEPT( 'Table', 'Table'[Product/Service], 'Table'[Client] ) )
		VAR  CountryString = CONCATENATEX( Countries, 'Table'[Country], ", " )
		RETURN  CurrentProduct & " ( " & CountryString & " ) ",
		", "
	)
	RETURN  Result

Hello @johnt75 

Your DAX works seamlessly. Thank you for the pompt and clear DAX. I am able to understand your DAX and the rationale! Thank you again. 

amitchandak
Super User
Super User

@JS , A new measure

Meausre =

Var _tab = client(Table, Table[Client], Table[Product/Service], "_1", concatenatex(Table, Table[Country]) , " , ")

return

concatenatex(_tab , _tab [Product/Service] & " - " & _tab [_1] , " , ")

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.