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
Asking
Regular Visitor

Counting Occurrences

Hi,

 

I have a table that is filtered on the dashboard based on ID:

ID Value

1   X

1   Y

2    X

2   Z

3   X

3   Y

if I used the function CONCATENATEX I can get a table like this

1 X,Y

2 X,Z

3 X,Y

 

What if I want to create a visual with the # of occurances of the concatenated value, meaning:

X.Y  2

X.Z  1

 

 

Thanks!

1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @Asking  ,

 

You can create a new column in table, the code is as follows:

 

Column = CONCATENATEX(FILTER('Table (2)','Table (2)'[ID]=EARLIER('Table (2)'[ID])),'Table (2)'[Value],",")

 

 

 

vxinruzhumsft_0-1669615064168.png

 

 

Then create a new table

Table 2 = var a=SUMMARIZE('Table (2)','Table (2)'[ID],'Table (2)'[Column])
 var b=SUMMARIZE(a,[Column])
 return ADDCOLUMNS(b,"count",COUNTAX(FILTER(a,[Column]=EARLIER('Table (2)'[Column])),[Column]))

vxinruzhumsft_1-1669880276783.png

 

 

 

 

 

 

Best Regards,

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-xinruzhu-msft
Community Support
Community Support

Hi @Asking  ,

 

You can create a new column in table, the code is as follows:

 

Column = CONCATENATEX(FILTER('Table (2)','Table (2)'[ID]=EARLIER('Table (2)'[ID])),'Table (2)'[Value],",")

 

 

 

vxinruzhumsft_0-1669615064168.png

 

 

Then create a new table

Table 2 = var a=SUMMARIZE('Table (2)','Table (2)'[ID],'Table (2)'[Column])
 var b=SUMMARIZE(a,[Column])
 return ADDCOLUMNS(b,"count",COUNTAX(FILTER(a,[Column]=EARLIER('Table (2)'[Column])),[Column]))

vxinruzhumsft_1-1669880276783.png

 

 

 

 

 

 

Best Regards,

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Asking
Regular Visitor

Thank you.

However, how do I create the actual table and not only get the scalar value please?

Greg_Deckler
Super User
Super User

@Asking Try this:

 

Measure = 
    VAR __Table = ADDCOLUMNS(SUMMARIZE('Table',[Column3]),"__Text",CONCATENATEX('Table',[Column2],","))
    VAR __Values = DISTINCT(SELECTCOLUMNS(__Table,"__Text",[__Text]))
    VAR __Table1 = ADDCOLUMNS(SUMMARIZE('Table',[Column1]),"__Text",CONCATENATEX('Table',[Column2],","))
    VAR __Table2 = FILTER(__Table1,[__Text] IN __Values)
    VAR __Result = COUNTROWS(DISTINCT(SELECTCOLUMNS(__Table2,"__Index",[Column1])))
RETURN
    __Result

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.