cancel
Showing results for
Did you mean:

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Frequent Visitor

## Rank with two fields

Hi all,

I have this table:

Company Count Rank

A              23      1

B              10      2

C               5      3

D               2      4

And with this DAX code works just fine

Rank =
RANKX(
ALLSELECTED(query)
,CALCULATE
( COUNT(query[Company]  ) ,ALLEXCEPT(query, query[Company] ) )
,,DESC,Dense
)

BUT, when i add a field to this output table: "Country", my output is this:

Company Count Country Rank

A              23       US         1

B              10       UK         2

C               5       AUS        1

D               2       ARG       4

How i should develop this my DAX code in order to obtain a Rank like mas first table above.?

Best

1 ACCEPTED SOLUTION
Frequent Visitor

Hello all,

Finally i've solved that way:

RANKX(
SUMMARIZE(
ALLSELECTED(A)
, A[Country.], A[Company]
)
, [Coun]
,,DESC,Dense
)

Coun =
CALCULATE(
COUNT(A[Company])
, FILTER(A, A[Country.]<>"")
)

Best
5 REPLIES 5
Frequent Visitor

Hello Ibendlin,

Company and Country: Columns

Count and Rank: Measures

Best

Super User

Cannot reproduce.

Frequent Visitor

Hello all,

Finally i've solved that way:

RANKX(
SUMMARIZE(
ALLSELECTED(A)
, A[Country.], A[Company]
)
, [Coun]
,,DESC,Dense
)

Coun =
CALCULATE(
COUNT(A[Company])
, FILTER(A, A[Country.]<>"")
)

Best
Frequent Visitor

** EDIT: I realize this doesnt exactly answer your question, but this may help someone else stumbling upon this post 🙂

You could try making a string concatenation of the two Rank Columns, then sort those alphabetically.

Concatenated =
Concatenate(
right(concatenate("000000",Value('Company Sales'[Rank Sales])),6),
Concatenate("_",right(concatenate("000000",'Company Sales'[Rank Customers]),6))
)

Rank Customers = Rankx('Company Sales','Company Sales'[Customers])

Rank Sales = Rankx(all('Company Sales'),'Company Sales'[Sales])

Dan Rolfe
Dobler Data Solutions
Super User

Is "Count"  a column or a measure?  Do you want the rank as a column or as a measure?

Announcements

#### Power BI Monthly Update - November 2023

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

#### Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

#### The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors