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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

HELP Please! VAR DAX

Hi There,

I am trying to replicate a formula I found on youtube but without success, would anyone know how to solve the problem

 

Formula that I am trying to copy:

Running Total = VAR ThisHeaderID = SELECTEDVALUE(Header[Header Sort])

                                VAR Result = CALCULATE([Magic Additive Total], ALL(Header), Header[Header Sort] <= ThisHeader ID)

                                RETURN Result

youtube.PNG

My formula:

Group Running Total = VAR GroupID = SELECTEDVALUE('Account & Account Group'[Groupp ID])
*I know the last 'Groupp ID' spelt wrong but I did it wrong in Excel so I just leave it

Power.PNG

1 ACCEPTED SOLUTION
v-robertq-msft
Community Support
Community Support

Hi, @Anonymous 

According to your DAX formula and error message, I think the true reason for this problem is that you didn’t use “return” to return the value you want the measure to return. Because if you used the “VAR” statement to define a variable, you have to use the "return" to return the result. You can try to change the DAX formula like this:

Grouping Running Total=
VAR GroupID=SELECTVALUE(‘Account & Account Group’[Group ID])
return
GroupID

More detail about “VAR” in DAX

 

Best Regards,

Community Support Team _Robert Qin

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
PhilipTreacy
Super User
Super User

Hi @Anonymous 

I'm perplexed as to what I've missed.  Was there something wrong with the answer I supplied on Friday?  Which says the same as the answer you accepted that was posted just a few hours ago?

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


v-robertq-msft
Community Support
Community Support

Hi, @Anonymous 

According to your DAX formula and error message, I think the true reason for this problem is that you didn’t use “return” to return the value you want the measure to return. Because if you used the “VAR” statement to define a variable, you have to use the "return" to return the result. You can try to change the DAX formula like this:

Grouping Running Total=
VAR GroupID=SELECTVALUE(‘Account & Account Group’[Group ID])
return
GroupID

More detail about “VAR” in DAX

 

Best Regards,

Community Support Team _Robert Qin

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

PhilipTreacy
Super User
Super User

Hi @Anonymous 

When you use VAR in  a measure you must use RETURN to return a value.  In this instance you don't need either VAR or RETURN, the measure can be simplified.

So the correct syntax is

 

Group Running Total = SELECTEDVALUE('Account & Account Group'[Groupp ID])

 

regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.