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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
sersanch
New Member

Rank column directly in table creation script?

Hi guys,

 

I'm trying to get a rank column in the same script I create a new table as follows, but reference inside filter to tmp1 is not accepted (tmp1 table not found). If I just return the table without the rank, and then add a new calculated column with the code below, it works fine. My question is, if there's a way to directly create the rank in the same script as table. Thanks to all!!

 

---------not working code--------

aidsByDateCarts =
   var tmp1 = FILTER(
                SUMMARIZE(train,
                          train[events.type],
                          train[timest].[Date],
                          train[events.aid],
                          "numEvents", COUNT(train[events.aid])),
                train[events.type]="carts")
    var tmp2 = ADDCOLUMNS(tmp1, "rank", RANKX(FILTER(tmp1, tmp1[Date]=EARLIER(tmp1[Date])),
                                                                                    [numEvents]))
    return tmp2
 
------- if I create later calculated column based on new table it works ok---------
RankByDate =
RANKX (
    FILTER(aidsByDateCarts, aidsByDateCarts[Date]=EARLIER(aidsByDateCarts[Date])),
    aidsByDateCarts[numEvents])
1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @sersanch 

You cannot use a variable name as a table reference. You can try by referring the column name only

aidsByDateCarts =
VAR tmp1 =
FILTER (
SUMMARIZE (
train,
train[events.type],
train[timest].[Date],
train[events.aid],
"numEvents", COUNT ( train[events.aid] )
),
train[events.type] = "carts"
)
VAR tmp2 =
ADDCOLUMNS (
tmp1,
"rank", RANKX ( FILTER ( tmp1, [Date] = EARLIER ( [Date] ) ), [numEvents] )
)
RETURN
tmp2

View solution in original post

1 REPLY 1
tamerj1
Super User
Super User

Hi @sersanch 

You cannot use a variable name as a table reference. You can try by referring the column name only

aidsByDateCarts =
VAR tmp1 =
FILTER (
SUMMARIZE (
train,
train[events.type],
train[timest].[Date],
train[events.aid],
"numEvents", COUNT ( train[events.aid] )
),
train[events.type] = "carts"
)
VAR tmp2 =
ADDCOLUMNS (
tmp1,
"rank", RANKX ( FILTER ( tmp1, [Date] = EARLIER ( [Date] ) ), [numEvents] )
)
RETURN
tmp2

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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