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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
rhinorocks
Frequent Visitor

Defining Variables

Hi All,

 

I am new to Dax and currently facing issues in defining variables. 

 

Can we define table columns in Variable? Like I have a Table called Customer Master and I want to define a variable storing the customer ID. But the error is coming as Var is expecting a scalar value? 

 

Kindly help!!

1 ACCEPTED SOLUTION

I think I got the solution of this issue. I was trying to write a measure instead of the calculated column. 

View solution in original post

5 REPLIES 5
rhinorocks
Frequent Visitor

Consider the following problem posted on this forum - 

 

https://community.powerbi.com/t5/Desktop/Days-between-two-dates-in-different-rows/m-p/2367394#M85183...

 

When I am trying to write this particular part of the code - 

 

Days between pricelists =
var _item = 'Table'[Item]
 
The tellisense is not able to detect this 'Table' hence I am not being able to proceed. Check the attached pictureIssues 1.png
While If I write the second line of the soluation, then I am getting no error. 
 
var _endDate = 'Table'[ValidityEndingDate]
 
Why is this happening?

 

I think I got the solution of this issue. I was trying to write a measure instead of the calculated column. 

Syk
Resident Rockstar
Resident Rockstar

You can work with columns in DAX but your measure has to return a scalar value. For example, in the dax below I'm storing a column in a variable but returning the sum of the column. If you reply with your specific use case, we may be able to help in more detail!

measure = 
var sales = 'sales'[sales_amount]

return sum(sales)

 

Hi Syk, I build similar logic, but it doesn't workCapture.PNG


@Syk wrote:

You can work with columns in DAX but your measure has to return a scalar value. For example, in the dax below I'm storing a column in a variable but returning the sum of the column. If you reply with your specific use case, we may be able to help in more detail!

 

measure = 
var sales = 'sales'[sales_amount]

return sum(sales)

 

 


 

Pragati11
Super User
Super User

Hi @rhinorocks ,

 

It depends on the logic and also on measure/column calculation you are trying to write using DAX.

Check this simple blog on variables:

https://www.purplefrogsystems.com/blog/2021/09/variables-in-dax/

 

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors