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
Anonymous
Not applicable

Create a variable in PowerBI with a filter

Hello Wonderful People

Please can someone point out the error in my syntax because PB error message for syntax is useless (or me?).  Thank you in advance.

test =
Var test =
CALCULATE(
SUM('Payment Report Template'[Payment Amount]),
FILTER('Payment Report Template','Payment Report Template'[Payment Type]="Practical Completion")
)
RETURN
1 ACCEPTED SOLUTION
Jayee
Responsive Resident
Responsive Resident

Hi @Anonymous 

 

After Retun need to specify variable or a calculation you want to return
check the below measure

test =

Var test =

CALCULATE(

SUM('Payment Report Template'[Payment Amount]),

FILTER('Payment Report Template','Payment Report Template'[Payment Type]="Practical Completion")

)

RETURN test

If this post helps, then please consider Accept it as the solution, Appreciate your Kudos!!

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Thank you for your quick response!  The syntax is now working.

serpiva64
Solution Sage
Solution Sage

Hi,

you missed to write the var after Return (test)

Jayee
Responsive Resident
Responsive Resident

Hi @Anonymous 

 

After Retun need to specify variable or a calculation you want to return
check the below measure

test =

Var test =

CALCULATE(

SUM('Payment Report Template'[Payment Amount]),

FILTER('Payment Report Template','Payment Report Template'[Payment Type]="Practical Completion")

)

RETURN test

If this post helps, then please consider Accept it as the solution, Appreciate your Kudos!!

Anonymous
Not applicable

Another question:

I am trying to create a variable which contains multiple variables but the syntax contains errors that I can't tell:

GFA_test =
VAR pc_as20_test =
    CALCULATE(DISTINCTCOUNT('Weekly Report Template'[D_Code]),FILTER('Weekly Report Template', 'Weekly Report Template'[Application Stage] =" 20 Funding Agreement Signed"))

VAR pc_as21_test =
    CALCULATE(DISTINCTCOUNT('Weekly Report Template'[D_Code]),FILTER('Weekly Report Template', 'Weekly Report Template'[Application Stage] =" 21 On Site Monitoring"))

VAR pc_as22_test =
    CALCULATE(DISTINCTCOUNT('Weekly Report Template'[D_Code]),FILTER('Weekly Report Template', 'Weekly Report Template'[Application Stage] ="22 Practical Completion - Retention Period (12m)"))

VAR pc_as23_test =
CALCULATE(DISTINCTCOUNT('Weekly Report Template'[D_Code]),FILTER('Weekly Report Template','Weekly Report Template'[Application Stage] ="23 Retention Payment - Application Closed"))







Jayee
Responsive Resident
Responsive Resident

One question per ticket please. If you need to extend your request then please raise a new ticket.

 

You will get a quicker response and each volunteer solver will get the kudos they deserve.

 

Thank you ! 

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.