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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

Want to write rank by each month per area DAX

Hi Team,

 

I need to calculate  rank by month per each area. If there is any null value/no value in sales column will asign lowset rank.

 

Power BI Link:  https://1drv.ms/u/s!Au-aOkl1BoHujVmkmN9Ws9yFCDSk?e=LQfhyt

 

Sample Data

Having first 3 columns are source columns , Rank-output which we need to generate , In the attached one drive file having original data posting requirement with sample data

 

rank.PNG

 

Output Visual:

 

visual.PNG

Thanks In Advance

 

Can you please help me out on this ?

1 ACCEPTED SOLUTION

In order to show anything in these cells, I'd recommend creating a dimension table for [Area].

AlexisOlson_0-1639940730748.png

(See attached.)

 

Then you can define blank to be a negative number like this:

RANKX (
    ALL ( Sheet1[Area] ),
    VAR SumSales =
        CALCULATE (
            SUM ( Sheet1[Sales] ),
            ALLEXCEPT ( Sheet1, Sheet1[YearMonth], Sheet1[Area] )
        )
    RETURN
        IF ( ISBLANK ( SumSales ), -1, SumSales )
)

View solution in original post

5 REPLIES 5
AlexisOlson
Super User
Super User

Ranking over Sheet1 isn't quite what you want since each area can have multiple rows per month.

 

Try this instead:

RANKX (
    ALL ( Sheet1[Area] ),
    CALCULATE (
        SUM ( Sheet1[Sales] ),
        ALLEXCEPT ( Sheet1, Sheet1[YearMonth], Sheet1[Area] )
    )
)
Anonymous
Not applicable

Hi @AlexisOlson ,

 

Thanks for the quick response. I am getting rank now but want to showcase rank to null values also.

 

For example: 

We want to assign maxrank+1 to all null values.

In the below example, We don't have sales in the area of C& K (Apr-2021) but we need to assign rank to all null values i.e.maxrank+1(15+1)

 

 

Assign Rank to null values

 

rank_null.PNG

Power BI Refrence Link: https://1drv.ms/u/s!Au-aOkl1BoHujVmkmN9Ws9yFCDSk?e=rEW41e

 

Thanks in advance

In order to show anything in these cells, I'd recommend creating a dimension table for [Area].

AlexisOlson_0-1639940730748.png

(See attached.)

 

Then you can define blank to be a negative number like this:

RANKX (
    ALL ( Sheet1[Area] ),
    VAR SumSales =
        CALCULATE (
            SUM ( Sheet1[Sales] ),
            ALLEXCEPT ( Sheet1, Sheet1[YearMonth], Sheet1[Area] )
        )
    RETURN
        IF ( ISBLANK ( SumSales ), -1, SumSales )
)
Anonymous
Not applicable

Hi @AlexisOlson ,

 

Awesome.This is working as expected But i want to know how it works?

i mean

1.why we need to use area column from derived PBI table instead of existing one ?(What is the difference between these two columns)

2. How negative value (i.e. in if condition we mention -1) giving maxrank+1 ?

 

Thanks in Advance.

 

The problem with the existing table is that there are no rows for "c" and "k" in Apr-21, so you run into an auto-exist problem where those cells won't show anything no matter how you define the measure.

 

I picked -1 rather arbitrarily. I assumed the smallest non-blank value would be zero and picked something less than that. Feel free to pick your favorite negative number instead.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

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.