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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Jcho10
Frequent Visitor

Variable in calculate Function

Hi everybody,

 

I'm a new user of Power BI and would like tu use variables in functions but i don't understand how it works.

I would like to use this function :

 

Part Privé N =
CALCULATE(

SUM([Solde]);[Exercice]=30/06/2016)

 

I would like to replace '30/06/2016' by a variable in order to change it easily.

 

Also, Il would like to use this same variable for other functions.

 

Could you please help me ?

 

Thank you

 

 

1 ACCEPTED SOLUTION
v-haibl-msft
Microsoft Employee
Microsoft Employee

@Jcho10

 

You can use variables as following formulas. Here [Latest_Exercice] is a measure which always returns the latest date. You can also use other measures which returns a value.

This is just a sample and we need to adjust the formulas according to the actual requirement.

 

Measure 1:

Latest_Exercice = MAX ( Table1[Exercice] )

 

Measure 2:

Part Privé N =
VAR Exercice = [Latest_Exercice]
RETURN
( CALCULATE ( SUM ( [Solde] ), Table1[Exercice] = Exercice ) )

 

Best Regards,

Herbert

View solution in original post

3 REPLIES 3
mohan_g_das1986
Helper III
Helper III

 Hi,

I am trying to calculate the YoY, QoQ & MoM using your Dax variable formula, but i am stuck at applying filters at calculated function

 

LastYR_WK = MAX(Timm[Week LY])
ST_WK_Filter =
Var Wk_No = [LastYR_WK]
RETURN
( CALCULATE(SUM(W12017[ST]),W12017[Week_Ref] = Wk_No ))
 
Table - W12017
Week_RefSTDate
2017W0120,99810/31/2016 0:00
2016W0118,93911/2/2015 0:00

 

Table - TIme

 

DateDate LYWeekWeek LY
10/31/2016 0:0011/2/2015 0:002017W012016W01
11/7/2016 0:0011/9/2015 0:002017W022016W02
10/30/2017 0:0010/31/2016 0:002018W012017W01
11/6/2017 0:0011/7/2016 0:002018W022017W02
v-haibl-msft
Microsoft Employee
Microsoft Employee

@Jcho10

 

You can use variables as following formulas. Here [Latest_Exercice] is a measure which always returns the latest date. You can also use other measures which returns a value.

This is just a sample and we need to adjust the formulas according to the actual requirement.

 

Measure 1:

Latest_Exercice = MAX ( Table1[Exercice] )

 

Measure 2:

Part Privé N =
VAR Exercice = [Latest_Exercice]
RETURN
( CALCULATE ( SUM ( [Solde] ), Table1[Exercice] = Exercice ) )

 

Best Regards,

Herbert

HI?

 

Thank you for your solution. It works well !

 

Sincerely

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.