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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

RANKX ADDCOLUMNS Variable table syntax issue

Hi All, I need help wiht a rankx within a variable table. I need to use variables instead of calculated columns as the measure I am using is dynamic and I don't want to use multiple calculated columns and switch functions. 

 

This is the first part of the solution, I will then add percentile rank and band results. 

 

TestTable:

DimensionValue
A1
B2
C3
D4

 

Dax code attempt:

 

Rank = 
Var Tbl =       SUMMARIZE('TestTable',
                'TestTable'[Dimension],
                "Measure",SUM(TestTable[Value]))
Var AddRank =   ADDCOLUMNS(Tbl,"Rank",RANKX(Tbl,[Measure]))
RETURN
SUMX(AddRank,[Rank])

 

 

The dax is currently returning a 1 for each dimension. Is there a way to use Rankx from a variable that is not a calculated column? I'm thought I might have seen a post perhaps related to this before following a really long search I cannot find a solution that works.

1 ACCEPTED SOLUTION
FrankAT
Community Champion
Community Champion

Hi @Anonymous 

one solution I found is the following formula (see figure 1), but it is equal with the shorter formula in figure 2.

 

Figure 1Figure 1

 

 Figure 2Figure 2

 

Some notes about your formula:

  1. You have used a varibale to create a virtual table, here: Var Tbl. In RANKX() you need the ALL() function that expects only a table reference, not a table expression like Tbl.29-08-_2020_01-31-04.png
  2. The measure Sum of TestTable[Value] should be calculated outside the formula.

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

View solution in original post

2 REPLIES 2
FrankAT
Community Champion
Community Champion

Hi @Anonymous 

one solution I found is the following formula (see figure 1), but it is equal with the shorter formula in figure 2.

 

Figure 1Figure 1

 

 Figure 2Figure 2

 

Some notes about your formula:

  1. You have used a varibale to create a virtual table, here: Var Tbl. In RANKX() you need the ALL() function that expects only a table reference, not a table expression like Tbl.29-08-_2020_01-31-04.png
  2. The measure Sum of TestTable[Value] should be calculated outside the formula.

With kind regards from the town where the legend of the 'Pied Piper of Hamelin' is at home
FrankAT (Proud to be a Datanaut)

Anonymous
Not applicable

Thakns so much @FrankAT, exactly what I need greatly appreciated.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.