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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Anonymous
Not applicable

Problem when creating a ranking using several tables in Power BI DAX

Hi team.

 

I'm trying to do this, for each couple year-month I need to create the ranking of my revenue. The rankin must restart everytime the year changes. This is an image of my model

 

db2907_0-1684429497470.png

And this is the formula that I've created:

 

Ranking Revenue =
VAR RevenuePerMonth =
    SUMX('sales', 'sales'[quantity] * RELATED('products'[price]))
RETURN
    RANKX(
        FILTER(
            ALL('datedim'),
            'datedim'[MonthNo] = MAX('datedim'[MonthNo]) ||
            'datedim'[Year] = MAX('datedim'[Year])
        ),
        RevenuePerMonth,
        ,
        ASC,
        Dense
    )
However, I'm getting always the same value when I create the table chart using the year and monthNo from the datedim table:
db2907_0-1684430384940.png

What is missing or what is wrong?

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

Variables in DAX aren't really variables, they're constants, so the RevenuePerMonth variable is only calculated once, it is not recalculated for each year / month combination. 

Take your code from the variable declaration and use it to create a new measure, and then reference that measure in your ranking code.

View solution in original post

3 REPLIES 3
johnt75
Super User
Super User

Variables in DAX aren't really variables, they're constants, so the RevenuePerMonth variable is only calculated once, it is not recalculated for each year / month combination. 

Take your code from the variable declaration and use it to create a new measure, and then reference that measure in your ranking code.

Anonymous
Not applicable

Thanks @johnt75  for your help. I have made the modifications and right now the metric is working. However, I would like to understand something. If I write this expression the ranking is ok:

 

Ranking Revenue Test =
    RANKX(
        ALL(DateDim[YYYYMM],'DateDim'[MonthNo]),
        [Revenue Measure],,
        DESC,
        Dense
    )
 
But, when I write this one the metric always returns the same value 1:
 
Ranking Revenue Test =
    RANKX(
        ALL(DateDim[YYYYMM],'DateDim'[MonthNo]),
        SUMX(sales, sales[quantity] * RELATED(products[price] )),,
        DESC,
        Dense
    )
 
What is happening in the second definition?

In the first version context transition is happening because you are calling a measure. In the second it is not happening and so the same value is being calculated for every row. If you wrapped the SUMX inside CALCULATE then it would work OK.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.