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
twilliams98103
Frequent Visitor

Count and rank combinations of values in two columns

I need to find the top n count of combinations across two columns. As a simplified example, given the following dataset:

 

COLORSTYLE
RedA
RedA
RedA
RedA
RedB
GreenA
GreenA
GreenB
GreenB
GreenB
BlueA
BlueC

 

I would need to determine that Red-A is the top combination with 4 occurences, Green-B second with 3, and Green-C third with 2, and display those three values (4,3,2) with meaningful lables. My actual dataset has millions of rows and thousands of unique combinations across the two columns. I have played around with the technique illustrated in this post but am not quite there. I have also reviewed some similar solutions using PowerQuery Group By but my connection type is DirectQuery, so I'm not sure if they will work.

 

For display I experimented with a matrix because I thought it would simplify the labelling, but the client would prefer a multi-line card, which I assume would require a concatenated label.

 

Thanks in advance for any help you can provide.

1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

@twilliams98103 

or even this

Table = 
var _tbl = SUMMARIZE(Table1;[STYLE];[COLOR];"Count";COUNTROWS(Table1))
return
ADDCOLUMNS(_tbl;"Rank";rankx(_tbl;[Count];;DESC)
)

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

4 REPLIES 4
az38
Community Champion
Community Champion

@twilliams98103 

or even this

Table = 
var _tbl = SUMMARIZE(Table1;[STYLE];[COLOR];"Count";COUNTROWS(Table1))
return
ADDCOLUMNS(_tbl;"Rank";rankx(_tbl;[Count];;DESC)
)

 

do not hesitate to give a kudo to useful posts and mark solutions as solution

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Hello, 

This solution helped me get what I was desiring. However, I would like to use a date slicer in my dashboard, and the output of this table does not dynamically change with this slicer. It does not allow me to create a relationship between this Table and my original table, Table1. The code is similar to what you showed above, but I'm unable to find away to embed the corresponding date/time value so that I can filter and then summarize the data.

 

Thanks!

tanmayvs_0-1634797883824.png

 

az38
Community Champion
Community Champion

Hi @twilliams98103 

try to create a calcualted table

Table = 
SUMMARIZE(Table1;[STYLE];[COLOR];"Count";COUNTROWS(Table1))

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
amitchandak
Super User
Super User

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.