Bird
Raised Fist0
Power BIbi_tool~20 mins

Variables (VAR/RETURN) in Power BI - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Variable Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ dax_lod_result
intermediate
1:30remaining
Calculate Total Sales Using Variables
Given the following DAX measure, what is the output if the Sales table has 3 rows with SalesAmount values 100, 200, and 300?

Measure = VAR Total = SUM(Sales[SalesAmount]) RETURN Total
Power BI
Measure = VAR Total = SUM(Sales[SalesAmount]) RETURN Total
A100
B300
C600
DSUM(Sales[SalesAmount])
Attempts:
2 left
💡 Hint
Think about what SUM does over all rows and how the variable stores that result.
🎯 Scenario
intermediate
2:00remaining
Using Variables to Improve Readability
You want to calculate the profit margin percentage as (Total Profit / Total Sales) * 100. Which DAX measure below correctly uses variables to calculate this?
AProfit Margin = VAR SalesTotal = SUM(Sales[SalesAmount]) RETURN SUM(Sales[Profit]) / SalesTotal * 100
BProfit Margin = SUM(Sales[Profit]) / SUM(Sales[SalesAmount]) * 100
CProfit Margin = VAR Profit = SUM(Sales[Profit]) RETURN Profit / SUM(Sales[SalesAmount]) * 100
DProfit Margin = VAR Profit = SUM(Sales[Profit]) VAR SalesTotal = SUM(Sales[SalesAmount]) RETURN DIVIDE(Profit, SalesTotal) * 100
Attempts:
2 left
💡 Hint
Using variables for both numerator and denominator improves clarity and performance.
🔧 Formula Fix
advanced
1:30remaining
Identify the Error in Variable Usage
What error will this DAX measure produce?

Measure = VAR Total = SUM(Sales[Amount]) RETURN Total + Total2
Power BI
Measure = VAR Total = SUM(Sales[Amount]) RETURN Total + Total2
AError: The variable 'Total2' is not defined.
BError: Syntax error near 'RETURN'.
CReturns double the sum of Sales[Amount].
DReturns the sum of Sales[Amount] without error.
Attempts:
2 left
💡 Hint
Check if all variables used in RETURN are declared.
❓ visualization
advanced
2:00remaining
Best Visualization for Comparing Variable Results
You created two variables in a measure: VAR Sales2023 and VAR Sales2024. You want to show their values side by side for each product category. Which visualization is best?
AClustered Column Chart with Product Category on axis and two measures for Sales2023 and Sales2024
BPie Chart showing combined Sales2023 and Sales2024 totals
CLine Chart with Product Category on axis and Sales2023 only
DTable showing only Sales2023 values
Attempts:
2 left
💡 Hint
You want to compare two values side by side across categories.
🧠 Conceptual
expert
2:30remaining
Understanding Variable Evaluation Context
Consider this DAX measure:

Measure = VAR TotalSales = SUM(Sales[Amount]) RETURN TotalSales + CALCULATE(SUM(Sales[Amount]), ALL(Sales))

What does this measure calculate?
Power BI
Measure = VAR TotalSales = SUM(Sales[Amount]) RETURN TotalSales + CALCULATE(SUM(Sales[Amount]), ALL(Sales))
AOnly total Sales ignoring filters
BSum of Sales in current filter context plus total Sales ignoring filters
CSum of Sales in current filter context multiplied by total Sales ignoring filters
DSum of Sales in current filter context only
Attempts:
2 left
💡 Hint
ALL removes filters, so CALCULATE returns total sales ignoring filters.

Practice

(1/5)
1. What is the main purpose of using VAR in a DAX formula?
easy
A. To store a value temporarily for reuse within the formula
B. To create a new table in the data model
C. To filter rows in a table
D. To format the output of a measure

Solution

  1. Step 1: Understand the role of VAR in DAX

    VAR is used to define a variable that holds a value temporarily inside a formula.
  2. Step 2: Identify what VAR does in calculations

    It allows reuse of the stored value to simplify and speed up calculations.
  3. Final Answer:

    To store a value temporarily for reuse within the formula -> Option A
  4. Quick Check:

    VAR stores values temporarily [OK]
Hint: VAR holds values inside formulas for reuse [OK]
Common Mistakes:
  • Thinking VAR creates tables
  • Confusing VAR with filters
  • Assuming VAR formats output
2. Which of the following is the correct syntax to define and return a variable in DAX?
easy
A. VAR Total = SUM(Sales[Amount]) RETURN Total
B. RETURN Total = SUM(Sales[Amount]) VAR Total
C. DEFINE VAR Total = SUM(Sales[Amount]) OUTPUT Total
D. LET Total = SUM(Sales[Amount]) THEN Total

Solution

  1. Step 1: Recall correct DAX variable syntax

    In DAX, variables are defined with VAR and the result is returned with RETURN.
  2. Step 2: Match syntax with options

    VAR Total = SUM(Sales[Amount]) RETURN Total uses VAR to define and RETURN to output, which is correct.
  3. Final Answer:

    VAR Total = SUM(Sales[Amount]) RETURN Total -> Option A
  4. Quick Check:

    VAR then RETURN is correct syntax [OK]
Hint: VAR first, then RETURN to output [OK]
Common Mistakes:
  • Swapping VAR and RETURN order
  • Using keywords like DEFINE or LET incorrectly
  • Missing RETURN keyword
3. Consider the following DAX measure:
Measure = VAR SalesAmount = SUM(Sales[Amount]) VAR Tax = SalesAmount * 0.1 RETURN SalesAmount + Tax

What is the output of this measure if the total sales amount is 1000?
medium
A. 100
B. 1100
C. 900
D. 10

Solution

  1. Step 1: Calculate SalesAmount variable

    SalesAmount = SUM(Sales[Amount]) = 1000.
  2. Step 2: Calculate Tax variable

    Tax = SalesAmount * 0.1 = 1000 * 0.1 = 100.
  3. Step 3: Calculate RETURN value

    Return SalesAmount + Tax = 1000 + 100 = 1100.
  4. Final Answer:

    1100 -> Option B
  5. Quick Check:

    1000 + 10% tax = 1100 [OK]
Hint: Calculate variables stepwise, then add in RETURN [OK]
Common Mistakes:
  • Using only SalesAmount without tax
  • Multiplying instead of adding tax
  • Confusing tax rate calculation
4. Identify the error in this DAX measure:
Measure = VAR TotalSales = SUM(Sales[Amount]) RETURN TotalSales * 0.1 VAR Tax = TotalSales * 0.1
medium
A. Variable names cannot have uppercase letters
B. RETURN keyword is missing
C. Variables must be defined before RETURN statement
D. SUM function cannot be used inside VAR

Solution

  1. Step 1: Review variable and RETURN order

    In DAX, all VAR definitions must come before the RETURN statement.
  2. Step 2: Identify misplaced VAR

    The variable Tax is defined after RETURN, which is invalid syntax.
  3. Final Answer:

    Variables must be defined before RETURN statement -> Option C
  4. Quick Check:

    All VAR before RETURN [OK]
Hint: Define all VAR before RETURN [OK]
Common Mistakes:
  • Placing VAR after RETURN
  • Ignoring syntax order rules
  • Assuming RETURN can appear multiple times
5. You want to create a measure that calculates the average sales per customer but only for customers with sales above 500. Which DAX measure using VAR and RETURN is correct?
hard
A. Measure = VAR FilteredSales = FILTER(Sales, Sales[Amount] < 500) VAR AvgSales = AVERAGEX(FilteredSales, Sales[Amount]) RETURN AvgSales
B. Measure = VAR AvgSales = AVERAGEX(Sales, Sales[Amount]) VAR FilteredSales = FILTER(Sales, Sales[Amount] > 500) RETURN AvgSales
C. Measure = RETURN VAR FilteredSales = FILTER(Sales, Sales[Amount] > 500) VAR AvgSales = AVERAGEX(FilteredSales, Sales[Amount])
D. Measure = VAR FilteredSales = FILTER(Sales, Sales[Amount] > 500) VAR AvgSales = AVERAGEX(FilteredSales, Sales[Amount]) RETURN AvgSales

Solution

  1. Step 1: Filter sales above 500

    VAR FilteredSales uses FILTER to keep only sales > 500, which matches the requirement.
  2. Step 2: Calculate average sales on filtered data

    VAR AvgSales uses AVERAGEX on FilteredSales to get average sales per customer.
  3. Step 3: Return the calculated average

    RETURN outputs AvgSales, the correct final result.
  4. Final Answer:

    Measure = VAR FilteredSales = FILTER(Sales, Sales[Amount] > 500) VAR AvgSales = AVERAGEX(FilteredSales, Sales[Amount]) RETURN AvgSales -> Option D
  5. Quick Check:

    Filter then average, return result [OK]
Hint: Filter first, then calculate average, then RETURN [OK]
Common Mistakes:
  • Defining variables after RETURN
  • Filtering sales less than 500 instead of greater
  • Returning variable before defining it
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard