Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
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
Solved! Go to Solution.
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
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?
Check out the July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
63 | |
59 | |
56 | |
38 | |
29 |
User | Count |
---|---|
82 | |
62 | |
45 | |
41 | |
40 |