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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.