Declare a variable containing a variable

dicken

Active Member
Joined
Feb 12, 2022
Messages
292
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I have a very simple table date, product code, units and have created a running total measure that allows me , when dropped into a pivot
table to retain all of the product I'd 's while only returning a running total for one, in this case 'a' .
<
abc :=
VAR mdate =
MAX ( Table1[Date] )
RETURN
IF (
CALCULATE (
SUM ( Table1[Units] ),
KEEPFILTERS ( Table1[Product] = "a" ),
FILTER (
ALL ( Table1[Date] ),
Table1[Date] <= mdate
&& Table1[Date] > EOMONTH ( mdate, -1 ) (so if true use)
)
),
VAR mdate =
MAX ( Table1[Date] )
RETURN
CALCULATE (
SUM ( Table1[Units] ),
KEEPFILTERS ( Table1[Product] = "a" ),
FILTER (
ALL ( Table1[Date] ),
Table1[Date] <= mdate
&& Table1[Date] > EOMONTH ( mdate, -1 ) (and if not return , I was hoping for a blank but get zero's)
)
),
" "
)


Now rather than having to type all out twice I'd like to write it once as a variable, so I could just then say ; if ( Vname, Vname, "" )
I've tried putting both variables at the start, and even pasted into "daxformatter.com' which is AMAZING, but not luck.


Richard.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top