My customer wanted to see the top 5 providers of a service in a Power BI Report. I added a RANKX calculation to the model.
RANK =rankx(all(Sales[Organization Name]),sum(Sales[Volume]),,DESC,Skip)
Here any filtering is removed to get all sales Organizations, then the sum of the Volume is used to rank the Organizations in descending order. The Skip will skip ranks on ties. So if two Organizations are ranked 3rd, then the next organization will be ranked 5th (skipping 4th).
|Organization||Rank||Sum of Volume|
In Power BI we can add a filter to the display to show just the top 5 organizations.
The filter is a shown below.
Including Our Company
My customer liked this but they had one more request. The wanted to always see our company so they could compare. Our company is Org X. In the example we are ranked 11th in this market. So how do you include us?
I came up with the following solution.
RankwithOrgX:=SWITCH(FIRSTNONBLANK(Sales[Organization Name],sum(Sales[Volume])),”Org X”,0,[Rank])
I use the FIRSTNONBLANK function to find our organization “Org X”. Using the switch function, I place a zero value for our Organization. For all other Organizations I use the value from the Rank calculation.
Org X shows as 0 under RankwithOrgX.
Now if we filter on RankwithOrgX less than or equal to 5. (remove our previous Rank filter)
Now our chart will include Our Company no matter its Rank.