DAX Variable

gavs73

Board Regular
Joined
Apr 22, 2008
Messages
138
Hi, I'm having trouble calling a variable in DAX ( assuming it is actually possible )...

I have a number of DAX statements similar to this:

d25:=CALCULATE([Creditx25],Data[Month]="32016",Data[PRODUCT]="Display")

Rather than changing "32016", I'd like to declare it as a variable, LMonth:="32016"

I've tried several ways of calling it, but all I get is errors...
d25:=CALCULATE([Creditx25],Data[Month]=[LMonth],Data[PRODUCT]="Display")
d25:=CALCULATE([Creditx25],Data[Month]=LMonth,Data[PRODUCT]="Display")
d25:=CALCULATE([Creditx25],Data[Month]='LMonth',Data[PRODUCT]="Display")
d10:=CALCULATE([Creditx10],Data[Month]=([LMonth]),Data[PRODUCT]="Display")

Thanks
Gav
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi Gav,

When you use a boolean expression as a filter argument for CALCULATE, it can't reference a measure (see https://msdn.microsoft.com/en-us/library/ee634825.aspx).

To get the result you want, you will have to use a table as your filter argument instead.

Something like this with a FILTER function should do it:
Code:
d25 :=
CALCULATE (
    [Creditx25],
    FILTER ( ALL ( Data[Month] ), Data[Month] = [LMonth] ),
    Data[PRODUCT] = "Display"
)

Note: The reason I used FILTER( ALL ( Data[Month] )...) is to replicate the 'overwrite' operation that CALCULATE would have performed if your filter argument were Data[Month] = "32016". In other words, existing filters on Data[Month] are cleared and replaced with the value of [LMonth] in the above measure.

Owen :)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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