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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Truelearner
Helper III
Helper III

Ranking in columns

Hi All 

 

I need ranks in columns ,below is the sample data and last three columns are the required ranks 

 

1. Rank of employee sales compared to all employees in the firm

2.Rank of employee sales compared to all employees in his department 

3. Rank of employee Department sales compared to all departments in the firm

 

NOTE : I want this ranks as columns not as measures 

 

DeptEmpHighlevellowlevelSalesEmp Firm RankEmp Rank in DeptEmp's Dept Rank
A11110632
B21120111
C31130723
A40140212
A51150322
B60160421
C70170613
A11140632
A11130632
C31150723
C31160723

 

@v-chuncz-msft @amitchandak @v-wxu  @mgwena @cham @amitchandak @Greg_Deckler @Mariusz @yij @yij @ v-diye-msft@ @v-eachen-msft @@v-juanli-msft @v-jayw-msf v-zhenbw-msft @harshnathani

2 ACCEPTED SOLUTIONS
harshnathani
Community Champion
Community Champion

Hi @Truelearner ,

1.jpg

Create Calculated Columns.

Venatas Employee Wise = CALCULATE(SUM('Table'[Ventas]),ALLEXCEPT('Table','Table'[Emp]))
Rango de la firma Emp1 = RANKX(ALL('Table'[Emp],'Table'[Venatas Employee Wise]),'Table'[Venatas Employee Wise],,ASC)
Venatas Department Wise = CALCULATE(SUM('Table'[Ventas]),ALLEXCEPT('Table','Table'[Departamento]))
Rango de Emp en el Departamento1 = RANKX(FILTER('Table','Table'[Departamento] = EARLIER('Table'[Departamento])),'Table'[Venatas Employee Wise],,ASC)
Rango de Departamento de Emp1 = RANKX(ALL('Table'[Departamento],'Table'[Venatas Department Wise]),'Table'[Venatas Department Wise],,ASC)

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

View solution in original post

mahoneypat
Microsoft Employee
Microsoft Employee

Since I had already started on these before seeing the post from @harshnathani , I will post these alternate solutions.  The difference is that these calculate it directly w/o an intermediate column.  Potentially a good example of using the Value term in RANKX on a virtual table (I learned something new on this one).

 

Emp Firm Rank New =
VAR summarytable =
    ADDCOLUMNS (
        SUMMARIZE ( Ranks, Ranks[Emp] ),
        "@Sales", CALCULATE (
            SUM ( Ranks[Sales] ),
            ALL ( Ranks ),
            Ranks[Emp] = EARLIER ( Ranks[Emp] )
        )
    )
VAR currentcontextsales =
    CALCULATE (
        SUM ( Ranks[Sales] ),
        ALL ( Ranks ),
        Ranks[Emp] = EARLIER ( Ranks[Emp] )
    )
RETURN
    RANKX ( summarytable, [@Sales], currentcontextsales, ASC )

 

Emp Rank in Dept New =
VAR summarytable =
    ADDCOLUMNS (
        SUMMARIZE (
            FILTER ( Ranks, Ranks[Dept] = EARLIER ( Ranks[Dept] ) ),
            Ranks[Emp]
        ),
        "@Sales", CALCULATE (
            SUM ( Ranks[Sales] ),
            ALL ( Ranks ),
            Ranks[Emp] = EARLIER ( Ranks[Emp] )
        )
    )
VAR currentcontextsales =
    CALCULATE (
        SUM ( Ranks[Sales] ),
        ALL ( Ranks ),
        Ranks[Emp] = EARLIER ( Ranks[Emp] )
    )
RETURN
    RANKX ( summarytable, [@Sales], currentcontextsales, ASC )

 

Emp Dept Rank New =
VAR summarytable =
    ADDCOLUMNS (
        SUMMARIZE ( Ranks, Ranks[Dept] ),
        "@Sales", CALCULATE (
            SUM ( Ranks[Sales] ),
            ALL ( Ranks ),
            Ranks[Dept] = EARLIER ( Ranks[Dept] )
        )
    )
VAR currentcontextsales =
    CALCULATE (
        SUM ( Ranks[Sales] ),
        ALL ( Ranks ),
        Ranks[Dept] = EARLIER ( Ranks[Dept] )
    )
RETURN
    RANKX ( summarytable, [@Sales], currentcontextsales, ASC )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
v-xuding-msft
Community Support
Community Support

Hi @Truelearner ,

 

Are the answers helpful? If you make sense, please accept as solution. More people will benefit from this thread.

 

 

Best Regards,
Xue Ding
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
mahoneypat
Microsoft Employee
Microsoft Employee

Since I had already started on these before seeing the post from @harshnathani , I will post these alternate solutions.  The difference is that these calculate it directly w/o an intermediate column.  Potentially a good example of using the Value term in RANKX on a virtual table (I learned something new on this one).

 

Emp Firm Rank New =
VAR summarytable =
    ADDCOLUMNS (
        SUMMARIZE ( Ranks, Ranks[Emp] ),
        "@Sales", CALCULATE (
            SUM ( Ranks[Sales] ),
            ALL ( Ranks ),
            Ranks[Emp] = EARLIER ( Ranks[Emp] )
        )
    )
VAR currentcontextsales =
    CALCULATE (
        SUM ( Ranks[Sales] ),
        ALL ( Ranks ),
        Ranks[Emp] = EARLIER ( Ranks[Emp] )
    )
RETURN
    RANKX ( summarytable, [@Sales], currentcontextsales, ASC )

 

Emp Rank in Dept New =
VAR summarytable =
    ADDCOLUMNS (
        SUMMARIZE (
            FILTER ( Ranks, Ranks[Dept] = EARLIER ( Ranks[Dept] ) ),
            Ranks[Emp]
        ),
        "@Sales", CALCULATE (
            SUM ( Ranks[Sales] ),
            ALL ( Ranks ),
            Ranks[Emp] = EARLIER ( Ranks[Emp] )
        )
    )
VAR currentcontextsales =
    CALCULATE (
        SUM ( Ranks[Sales] ),
        ALL ( Ranks ),
        Ranks[Emp] = EARLIER ( Ranks[Emp] )
    )
RETURN
    RANKX ( summarytable, [@Sales], currentcontextsales, ASC )

 

Emp Dept Rank New =
VAR summarytable =
    ADDCOLUMNS (
        SUMMARIZE ( Ranks, Ranks[Dept] ),
        "@Sales", CALCULATE (
            SUM ( Ranks[Sales] ),
            ALL ( Ranks ),
            Ranks[Dept] = EARLIER ( Ranks[Dept] )
        )
    )
VAR currentcontextsales =
    CALCULATE (
        SUM ( Ranks[Sales] ),
        ALL ( Ranks ),
        Ranks[Dept] = EARLIER ( Ranks[Dept] )
    )
RETURN
    RANKX ( summarytable, [@Sales], currentcontextsales, ASC )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


harshnathani
Community Champion
Community Champion

Hi @Truelearner ,

1.jpg

Create Calculated Columns.

Venatas Employee Wise = CALCULATE(SUM('Table'[Ventas]),ALLEXCEPT('Table','Table'[Emp]))
Rango de la firma Emp1 = RANKX(ALL('Table'[Emp],'Table'[Venatas Employee Wise]),'Table'[Venatas Employee Wise],,ASC)
Venatas Department Wise = CALCULATE(SUM('Table'[Ventas]),ALLEXCEPT('Table','Table'[Departamento]))
Rango de Emp en el Departamento1 = RANKX(FILTER('Table','Table'[Departamento] = EARLIER('Table'[Departamento])),'Table'[Venatas Employee Wise],,ASC)
Rango de Departamento de Emp1 = RANKX(ALL('Table'[Departamento],'Table'[Venatas Department Wise]),'Table'[Venatas Department Wise],,ASC)

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors