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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
felipereyes_
Frequent Visitor

Doing a rank with a column created in variable

Hi everyone,

 

I need to rank the Sales of the Employees, but I have a table and a new column called Test created as a variable in th DAX. This is to improve the performance. I have tried it without and it is taking too long to load, so this is my only solution. The loading time is no problem anymore but now I dont know how to iterate through the new column Test to get the ranking right. I need to use that column (which is a replication of the column Sales) because the column Sales is based on a lot of measures, which is the reason why it takes so long to load.

The query is executing but the rankings come out all as 1. It must be due to the SUMX() that just compares every row with itself. How can I fix this? 

Your help is gretaly apreciated. 

 

Measure =
VAR table_ =
    ADDCOLUMNS (
        SUMMARIZE (
            'TableEmployee',
            'TableEmployee'[Employee],
            "Sales", 'TableSales'[Sales]
        ),
        "Test", [Sales]
    )
RETURN
RANKX( ALLSELECTED( 'TableEmployee'[Employee] ) , ( SUMX(table_, [Test])),,ASC,Dense)
3 REPLIES 3
Dangar332
Super User
Super User

hi, @felipereyes_ 

try below

Measure =
VAR table_ =
    ADDCOLUMNS (
        SUMMARIZE (
            'TableEmployee',
            'TableEmployee'[Employee],
            "Sales", 'TableSales'[Sales]
        ),
        "Test", [Sales]
    )
RETURN
RANKX(table_ ,[test],,ASC,Dense)


     or
measure =
rank(
  crossjoin(
    all('TableEmployee'[Employee]),
    all('TableSales'[Sales])
  ),
orderby([sales],asc)
)

Hi! Thanks for your reply! The first option is not working because the newly created column and table cannot go just like this in the Rankx. That is why I usd SUMX() but I only get 1s for every row. And the second option is not working either, and also referring to the measure Sales, which is wanted to avoid. Do you have any other suggestions?

Hi, @felipereyes_ 

provide some data

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.