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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
thangmcsa
New Member

How to apply Measure in Dax Studio

Hi All, 

I would like to add a rank column for virtual table created by Dax function, my code as below 

DEFINE
	MEASURE Sales[sale_amount] = sumx(Sales, Sales[Quantity] * Sales[Net Price])
	

	var temp = SUMMARIZECOLUMNS (
	    Customer[Country],
	    "Sales Amount1",Sales[sale_amount]
	
		)
EVALUATE
	ADDCOLUMNS(temp, "rankx",rankx(
	    		Customer[Country],
	    		Sales[sale_amount]
			)
		)

I got the error say "Table variable name 'temp' can not be used in the current context because a base table is expected" , this mean Rankx function can not work with virtual  table created by Dax code ?? 

 

Dataset used in the lab from this link Introducing RANKX in DAX 

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

Please try something like below.

 

DEFINE
    MEASURE Sales[sale_amount] =
        SUMX ( Sales, Sales[Qualtity] * Sales[Net Price] )
    VAR temp =
        SUMMARIZECOLUMNS ( Customer[Country], "Sales Amount1", Sales[sale_amount] )

EVALUATE
ADDCOLUMNS (
    temp,
    "rankx", RANKX ( VALUES ( Customer[Country] ), Sales[sale_amount] )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


hi @Jihwan_Kim ,

The code provided work as well, however could you please help clarify why we can not use the code below ?

"rankx", RANKX ( VALUES ( temp[Country] ), temp[Sales Amount1] )

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors