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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
felipefrutuoso
Frequent Visitor

rankx using column of variable table

Why I cannot do this?

EVALUATE
VAR myvirtuatable = ADDCOLUMNS(
    SUMMARIZE(
        FILTER('table_a',[field]=666),        
        'table_a'[field2],
        'table_a'[field3]
             ),
    "total", CALCULATE(sum('table_a'[value]))
        )

RETURN ADDCOLUMNS(myvirtuatable,"RANK",RANKX(myvirtuatable,total,,DESC))

"cannot find this name, "total"

1 ACCEPTED SOLUTION
edhans
Super User
Super User

You can, your syntax is off just a bit though @felipefrutuoso 

When you create a table using a variable, if the function can see the table (iterators can, aggregators cannot), the field name has to be wrapped in square brackets.

 

EVALUATE
VAR myvirtuatable =
    ADDCOLUMNS(
        SUMMARIZE(
            FILTER(
                'table_a',
                [field] = 666
            ),
            'table_a'[field2],
            'table_a'[field3]
        ),
        "total",
            CALCULATE(
                SUM( 'table_a'[value] )
            )
    )
VAR Result = 

    ADDCOLUMNS(
        myvirtuatable,
        "RANK",
            RANKX(
                myvirtuatable,
                [total],   <---- Adjustment to syntax
                ,
                DESC
            )
    )
RETURN
	Result

See if that works for you.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

1 REPLY 1
edhans
Super User
Super User

You can, your syntax is off just a bit though @felipefrutuoso 

When you create a table using a variable, if the function can see the table (iterators can, aggregators cannot), the field name has to be wrapped in square brackets.

 

EVALUATE
VAR myvirtuatable =
    ADDCOLUMNS(
        SUMMARIZE(
            FILTER(
                'table_a',
                [field] = 666
            ),
            'table_a'[field2],
            'table_a'[field3]
        ),
        "total",
            CALCULATE(
                SUM( 'table_a'[value] )
            )
    )
VAR Result = 

    ADDCOLUMNS(
        myvirtuatable,
        "RANK",
            RANKX(
                myvirtuatable,
                [total],   <---- Adjustment to syntax
                ,
                DESC
            )
    )
RETURN
	Result

See if that works for you.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

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.