The SWITCH function checks an expression against a list of values and returns the result corresponding to the first matching value. If no match is found, it can return a default value.
The correct syntax starts with the expression, followed by value-result pairs, and an optional default.
If SWITCH does not find a matching value and no default is given, what does it return?
AError
BBLANK()
CZero
DThe first result
✗ Incorrect
SWITCH returns BLANK() when no match and no default value are provided.
Which scenario is best suited for SWITCH instead of nested IFs?
AChecking multiple unrelated conditions
BFiltering rows in a table
CSumming values in a column
DChecking one expression against many possible values
✗ Incorrect
SWITCH is best when you compare one expression to many values.
Can SWITCH evaluate multiple different expressions at once?
ANo, it evaluates only one expression
BOnly if nested inside IF
CYes, it can evaluate multiple expressions
DOnly with a default value
✗ Incorrect
SWITCH evaluates only one expression and compares it to multiple values.
Explain how the SWITCH function works and when you would use it in Power BI.
Think about choosing from many options based on one question.
You got /5 concepts.
Describe the difference between SWITCH and nested IF statements in DAX.
Consider how easy it is to read and write each.
You got /4 concepts.
Practice
(1/5)
1. What does the SWITCH function do in Power BI?
easy
A. It filters rows based on a condition.
B. It creates a new table from existing data.
C. It chooses a result based on matching values or conditions.
D. It sums values in a column.
Solution
Step 1: Understand the purpose of SWITCH
The SWITCH function evaluates an expression and returns a result based on matching values or conditions.
Step 2: Compare with other functions
Unlike filtering or summing, SWITCH simplifies multiple IF conditions into one formula.
Final Answer:
It chooses a result based on matching values or conditions. -> Option C
Quick Check:
SWITCH picks result by matching values [OK]
Hint: Remember: SWITCH picks output based on matching input [OK]
Common Mistakes:
Confusing SWITCH with filtering functions
Thinking SWITCH creates tables
Assuming SWITCH sums values
2. Which of the following is the correct syntax for a basic SWITCH function in DAX?
easy
A. SWITCH(<expression>, <value1>, <value2>, <result1>, <result2>, <else_result>)
B. SWITCH(<value1>, <result1>, <value2>, <result2>, <else_result>)
C. SWITCH(<expression>, <result1>, <value1>, <result2>, <value2>, <else_result>)
D. SWITCH(<expression>, <value1>, <result1>, <value2>, <result2>, <else_result>)
Solution
Step 1: Recall SWITCH syntax
The correct syntax is SWITCH(expression, value1, result1, value2, result2, else_result).
Step 2: Check option correctness
SWITCH(<expression>, <value1>, <result1>, <value2>, <result2>, <else_result>) matches the correct order: expression first, then pairs of value and result, ending with else result.
Final Answer:
SWITCH(<expression>, <value1>, <result1>, <value2>, <result2>, <else_result>) -> Option D
C. Conditions should be separated by commas, not line breaks.
D. Sales[Amount] cannot be compared with numbers.
Solution
Step 1: Analyze SWITCH with TRUE()
Using TRUE() allows SWITCH to evaluate conditions in order.
Step 2: Check for ELSE result
No ELSE (default) result is provided, so if none match, result is blank or error.
Final Answer:
Missing ELSE result for unmatched conditions. -> Option A
Quick Check:
Always add ELSE result in SWITCH with TRUE() [OK]
Hint: Add ELSE result to cover all cases [OK]
Common Mistakes:
Forgetting ELSE result causes blanks
Thinking TRUE() is invalid in SWITCH
Misunderstanding condition order
5. You want to create a measure that categorizes sales amount into "Very High" (above 2000), "High" (1001-2000), "Medium" (501-1000), "Low" (1-500), and "No Sales" (0 or less). Which SWITCH formula correctly implements this?
Step 1: Use SWITCH with TRUE() for condition checks
Using SWITCH(TRUE(), ...) allows checking conditions in order from highest to lowest.
Step 2: Verify condition ranges and order
SWITCH(TRUE(), Sales[Amount] > 2000, "Very High", Sales[Amount] > 1000, "High", Sales[Amount] > 500, "Medium", Sales[Amount] > 0, "Low", "No Sales") correctly uses > 2000, > 1000, > 500, > 0, then else "No Sales". This covers all ranges without overlap.
Step 3: Check other options for errors
SWITCH(Sales[Amount], >2000, "Very High", >1000, "High", >500, "Medium", >0, "Low", "No Sales") has invalid syntax (cannot use >2000 as value). Options A and D use >= which changes boundaries and may overlap or miss exact ranges.