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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
iplaygod
Resolver I
Resolver I

DAX: How update a variable value after having defined the variable?

I am writing DAX

In most other coding languages, I can define a variable, give it a value, and then later on in the code change or add to that value.
Eg:

VAR myVariable = 1
//later in the code:
myVariable = 2

Is this possible in DAX?
Or can I only set variable values when I define them with the VAR statement?

I want to concatenate strings by adding them onto a string variable.
I can not use CONCATENATEX in this situation.

So I want to do
VAR concatString = ""

//then later in the code
concatString = concatString & "|" & newValue

is this possible? please give me example code if it is.

Also, a sidenote question:
What happens if I re-define a variable with the same name?
Do I then "wipe out" the previous variable with the same variable name?

thanks in advance

1 ACCEPTED SOLUTION

Hi @iplaygod,

 

Hope this document about naming syntax of variable is helpful to you.

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @iplaygod,

 

I don't think we can re-define a variable with the same name. 

 

If you want to achieve below formula
VAR concatString = ""

//then later in the code
concatString = concatString & "|" & newValue

 

You may need to define two different variables like this:

VAR concatString = ""
VAR concatString2 = concatString & "|" & newValue

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ok thanks

so follow-up question...

 

is it possible to create a variable and naming it by using a string?

like in Power Query (M) language you can use

#"myVariable"

 

is there a similar alternate syntax for defining / naming variables in DAX?

Hi @iplaygod,

 

Hope this document about naming syntax of variable is helpful to you.

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.