Using CONCATENATEX with Distinct count of each value

naveeddil

New Member
Joined
Nov 5, 2015
Messages
46
Office Version
  1. 365
Platform
  1. Windows
Dear Experts,

I am trying to use DAX function in excel by showing Distinct values using concatenateX and would like to join Distinct count with it for individual values.

i.e.

Sydney
Sydney
NY
NY
NY
TX
CT
CT

OUTPUT required:
Sydney 2, NY 3, TX 1, CT2


Currently I am using
Excel Formula:
=CONCATENATEX(DISTINCT(Table2[Adj_Distr]), Table2[Adj_Distr] ,", ")

and it is giving me only

Sydney, NY, TX, CT


Appreciated,
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Update

I tried to do it successfully for single item in a cell by using following
Excel Formula:
=CONCATENATEX(DISTINCT(Table2[Adj_Province]), Table2[Adj_Province] ,", ")&" ("&COUNT([Adj_Province])&")"

Although it is not working for multiple items within same cell

In third column of below picture, I want to write individual count for each district instead of total at the end

i.e. Karachi (12), Tando M Khan (4)

ConcatenateX.png
 
Upvote 0
Here is an overview of the requirement

ConcatenateX.png



HEre is the dataset:

07-Jul-2021AjkNeelumNo-
07-Jul-2021PunjabMultanNo
07-Jul-2021PunjabMultanYes
07-Jul-2021PunjabSargodhaNo
07-Jul-2021PunjabLahoreNo
07-Jul-2021PunjabRawalpindiNo
07-Jul-2021PunjabRawalpindiNo
07-Jul-2021PunjabGujranwalaNo
07-Jul-2021SindhTando M KhanNo
07-Jul-2021SindhKarachiNo
07-Jul-2021SindhKarachiNoPancreatic Pathology
07-Jul-2021SindhKarachiNo
07-Jul-2021SindhKarachiNo
07-Jul-2021SindhKarachiNo
07-Jul-2021SINDHKarachiNO
07-Jul-2021SINDHKarachiNO
07-Jul-2021SINDHKarachiNO
07-Jul-2021SINDHKarachiNONO
07-Jul-2021SINDHKarachiNONO
07-Jul-2021SindhKarachiNo
07-Jul-2021SindhKarachiNo
07-Jul-2021SindhKarachiNo
07-Jul-2021SindhKarachiNo
07-Jul-2021SindhKarachiNo
 
Last edited:
Upvote 0
Please try

Rich (BB code):
=Var Tab = SUMMARIZE(Table2,[Adj_Province],"Count",COUNTROWS(Table2))
return CONCATENATEX(Tab, [Adj_Province] &"(" & [Count] &")",", ")

or

Rich (BB code):
=Var Tab = SUMMARIZE(Table2,Table2[Adj_Distr],"Count",COUNTROWS(Table2))
return CONCATENATEX(Tab, [Adj_Distr] &"(" & [Count] &")",", ")
 
Upvote 0
Solution
Dear I am trying to use it in excel pivot table which doesnt support var and return functions
 
Upvote 0
Really?
I did this in Excel
 

Attachments

  • DAX.png
    DAX.png
    140.6 KB · Views: 116
Upvote 0
Please try

Rich (BB code):
=Var Tab = SUMMARIZE(Table2,[Adj_Province],"Count",COUNTROWS(Table2))
return CONCATENATEX(Tab, [Adj_Province] &"(" & [Count] &")",", ")

or

Rich (BB code):
=Var Tab = SUMMARIZE(Table2,Table2[Adj_Distr],"Count",COUNTROWS(Table2))
return CONCATENATEX(Tab, [Adj_Distr] &"(" & [Count] &")",", ")

Perfectly Worked!

It was giving some error earlier and just noticed that actually it was Table Name error :)


THANK YOU :-)
 
Upvote 0

Forum statistics

Threads
1,224,922
Messages
6,181,781
Members
453,065
Latest member
jfrsanders

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top