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
giorgiokatr
Helper V
Helper V

wrong rank in negative values

wrong rank in negative values

 

when i select sector and area hierarchy rank for negative values (category bikes) goes wrong

after branch 6 branch 2 should have rank 2

also rank should start from 4

see attached pbix

https://drive.google.com/open?id=0Bw-_YmJ3Q49gTnpKTnQzNktTZ1k

1 ACCEPTED SOLUTION

@giorgiokatr what about :

 

First create a measure to sum [Total USD], like :

Sum_USD = SUM(temp[Total USD])

Then rank all table  and use the last measure as expression:

 

 

Rank = RANKX(ALLSELECTED(temp),[Sum_USD],,ASC,Dense)

 

No filters appliedCapture.PNG

Filter

cat = {a,b}

Capture.PNG

 

filter

 

firstCat={1} and

cat={b,c}

 

Capture.PNG

 

In this way you will rank the values according to what is selected.

 

 

View solution in original post

9 REPLIES 9
Eric_Zhang
Employee
Employee


@giorgiokatr wrote:

wrong rank in negative values

 

when i select sector and area hierarchy rank for negative values (category bikes) goes wrong

after branch 6 branch 2 should have rank 2

also rank should start from 4

see attached pbix

https://drive.google.com/open?id=0Bw-_YmJ3Q49gTnpKTnQzNktTZ1k


@giorgiokatr wrote:

wrong rank in negative values

 

when i select sector and area hierarchy rank for negative values (category bikes) goes wrong

after branch 6 branch 2 should have rank 2

also rank should start from 4

see attached pbix

https://drive.google.com/open?id=0Bw-_YmJ3Q49gTnpKTnQzNktTZ1k

@giorgiokatr

Even with the attached pbix file, your description is not clear for me. Could you show the expected output with some snapshots?

please check two attached picsright rank.pngwrong rank.pngthank @Eric_Zhang

In order to better understand you issue please share how are you claculating the rank. 

i want to calculate sales so i created a measure

salesamount = CALCULATE(SUM(Table1[sales]))

then i used

Rank = RANKX(ALL(Table1[branch]),CALCULATE([salesamount],ALLEXCEPT(Table1,Table1[branch],Table1[area],Table1[sector])),,ASC,Dense)

the "hierarchy" in matrix rows is sector>area>branch

but rank is wrong for negative when i filter for example sector or area in slicers

i also used

RANKX(ALL(Table1[branch]),CALCULATE([salesamount]),,ASC,Dense)

but same problem

rank goes 1,2 then in negative values rank is 4 instead of 3

this happen when i filter with a slicer

all branch rank (unfiltered area and sector ) is right

@giorgiokatr  you might need to nest the formula with hasonevalue( ).

 

See this really nice post from  @Anonymous  http://community.powerbi.com/t5/Desktop/Using-RankX-in-DAX-For-PowerPivot-PowerBI/m-p/42824 

 

Take this example:

 

Capture.PNG

Rank by visible = if (
                       HASONEVALUE(temp[cat]),
					   RANKX(ALLSELECTED(temp[cat]),[Total USD],,ASC,Dense)
					   )

thanks @Bordalos it works ok but the problem is when you have an upper hierarchy in the cat and you filter it.

example

 

try this in a power bi

and create two slicers one for first cat and a second for cat

if you filter by first cat (example first cat =1)

u will see wrong rank for

RANKX(ALLSELECTED(temp[cat]),[Total USD],,ASC,Dense)
first catcatTotal USD
1a50
1b20
1c-10
2d-20

@giorgiokatr what about :

 

First create a measure to sum [Total USD], like :

Sum_USD = SUM(temp[Total USD])

Then rank all table  and use the last measure as expression:

 

 

Rank = RANKX(ALLSELECTED(temp),[Sum_USD],,ASC,Dense)

 

No filters appliedCapture.PNG

Filter

cat = {a,b}

Capture.PNG

 

filter

 

firstCat={1} and

cat={b,c}

 

Capture.PNG

 

In this way you will rank the values according to what is selected.

 

 

thanks @Bordalos!! that did the trick!

Hello @Eric_Zhang

Any ideas?

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.