0
0
Power BIbi_tool~20 mins

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

Choose your learning style9 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.