Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
paguy215
Helper III
Helper III

RANKX Returning All as 1

I'm trying to rank agents based on their sales over a selected date range.  At first it was takiing too much memory to even bring on the visual

 

so i ended up creating a new query to aggregate things there, and I can get the RANKX on the visual fairly easily...however now everything is ranked as 1

 

here is what i have

 

Revenue Rank =
RANKXALLSELECTED('Agent List'[AgentID]), calculate(sum(Query1[SalesSum])))
 
The fields in the 'Query1' Are a date, agent ID (that ties to the 'Agent List' table), and two columns for two different sale types, with 'SalesSum' being the calculated column adding those together.
 
Any help is appreciated.
4 REPLIES 4
v-linhuizh-msft
Community Support
Community Support

Thanks for the reply from Greg_Deckler.

 

Hi @paguy215 ,

 

Make sure you are using the AgentID field from the Agent List table in the visual, it returns the correct result in my test.

vlinhuizhmsft_0-1737700416962.png

Thanks, but still doesn't work and I'm using the right fields.   Also in what you shared, I see the ranks are still off (IE two rows ranked 1st but with different SalesSum totals.

 

Also, I wouldn't have a row for each date...the idea would be a row for each agent, summing the total within a range of dates

Greg_Deckler
Super User
Super User

@paguy215 RANKX is notoriously finicky. I would try using RANK instead. Or, see if this helps:



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

But in case you need to further condition the range

I'm trying to calculate an agency's ranking using the RANKX formula, but I can't figure it out.

What I am trying to do is for the ranking to be calculated taking into account the investment of each agency, but this cannot consider agencies with negative YoY, they must be excluded from the ranking. I only want a ranking of Agencies that have a positive % variation (2023 vs 2024).


I am using the following formula but without much success.

RANKX Agencia 1 Pos =
VAR InversionYTD = [Inversión neta YTD Agencia]
VAR VariacionYTD = [Variación YTD Agencia]
RETURN
IF(
NOT ISBLANK(InversionYTD) && InversionYTD <> 0 && VariacionYTD > 0,
RANKX(
            FILTER(
                           ALLSELECTED('Industria'[Agencia]),
                                   [Variación YTD Agencia] > 0
                       ),
           CALCULATE(
                                  [Inversión neta YTD Agencia],
                                             REMOVEFILTERS('Industria'[Anunciante]), -- Delete filters of advertiser column
                             ),
                             ,
            DESC,
           Dense
                      ),
           BLANK()

)

 

 

 

The expected result would be a matrix visual object like the one in the image.

mlozano_0-1737681335027.png

 



Expected result

AnuncianteAgencia20232024DiffYoYRankx
TECNOQUIMICASSANCHO/BBDO$ 364,529$ 435,109$ 70,58019%1
CENTRAL CERVECERASANCHO/BBDO$ 180$ 32,094$ 31,91517744%1
PEPSI COL+POSTOBONSANCHO/BBDO$ 3,856$ 20,385$ 16,529429%1
ALMACENES EXITOSANCHO/BBDO$ 65,194$ 79,979$ 14,78523%1
BANCOLOMBIASANCHO/BBDO$ 45,218$ 59,528$ 14,30932%1
ALIMENTOS POLARSANCHO/BBDO$ 14,610$ 26,580$ 11,97082%1
MERCADOLIBRE.COMSANCHO/BBDO$ 14,966$ 24,951$ 9,98667%1
PEPSICO ALIMENTOSSANCHO/BBDO$ 11,078$ 17,517$ 6,43958%1
ECOPETROLSANCHO/BBDO$ 8,340$ 12,604$ 4,26451%1
LEADERS+CEETSANCHO/BBDO$ 2,234$ 5,461$ 3,226144%1
C FUNCIONAL BEBIDASSANCHO/BBDO$ 965$ 3,937$ 2,972308%1
DAIMLER COLOMBIA SASANCHO/BBDO$ 2,167$ 5,033$ 2,865132%1
TERPELSANCHO/BBDO$ 1,763$ 4,196$ 2,433138%1
AVON CALLINGSSANCHO/BBDO$ 268$ 1,493$ 1,225456%1
ARTURO CALLESANCHO/BBDO$ 301$ 1,380$ 1,079359%1
CORONASANCHO/BBDO$ 2,397$ 2,782$ 38516%1
L&C S.A.SSANCHO/BBDO$ 892$ 1,238$ 34639%1
PJ COL SASSANCHO/BBDO$ 478$ 812$ 33470%1
ALM EXITO+B COLPATSANCHO/BBDO$ 83$ 230$ 147176%1
COLGATE PALMOLIVEYOUNG & RUBICAM$ 159,954$ 257,348$ 97,39461%2
COLGATE PALMOLIV INTYOUNG & RUBICAM$ 9,363$ 31,787$ 22,424240%2
HUAWEI TECHNOLOGIESYOUNG & RUBICAM$ 541$ 3,313$ 2,772512%2
DERCO SAYOUNG & RUBICAM$ 3,175$ 4,147$ 97231%2
WALT DISNEY COMPANYBTL$ 145,513$ 254,319$ 108,80675%3



I have the following table

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.