Logical DAX
Classify values without confusing zero with missing
Logical DAX turns a condition into a decision. A retail manager may want a sales band for every line, but an unreported sale amount must not be interpreted as a confirmed zero. IF(test, true_result, false_result) chooses a result; SWITCH(expression, value, result, ..., else) compares alternatives. SWITCH(TRUE(), condition, result, ..., else) evaluates ordered conditions and returns the first matching result. Keep branch result types consistent.
Use the isolated Import table ScalarSales from labs/dax-scalar-functions/scalar-sales.csv. In Power Query, explicitly set LineID, Region, ProductCode, ProductName and UnitsText to Text; RevenueUSD to Fixed Decimal Number. Empty RevenueUSD fields must be null, not zero or text. Model culture: en-US; no relationships or RLS. Each row is a synthetic sale-line observation, including two observations with unreported revenue. Currency is USD; no taxes or returns. All results are expected, not native execution evidence. Run each EVALUATE query separately in DAX Query View without report slicers. For a measure or calculated column, create each named definition separately in the appropriate model editor.
Example 1 — Sales bands as a calculated column
Create this column on ScalarSales. The thresholds are a fictional business rule, not a universal sales policy.
Sales Band =VAR Amount = ScalarSales[RevenueUSD]RETURN SWITCH(TRUE(), ISBLANK(Amount), "Missing", Amount == 0, "Zero", Amount < 50, "Low", Amount < 100, "Standard", "High")| Line | Revenue USD | Expected band |
|---|---|---|
| S01 | 0 | Zero |
| S02 | 20 | Low |
| S03 | 49 | Low |
| S04 | 50 | Standard |
| S05 | 100 | High |
| S06 | blank | Missing |
| S07 | blank | Missing |
Test missing first, then zero, then increasing thresholds. A test for < 100 placed ahead of < 50 would swallow Low rows. These bands are materialized for the Import column during model calculation; selecting a slicer filters existing band values, it does not recalculate their thresholds. Use a measure instead for a band based on the currently selected aggregate.
Example 2 — Blank checks, fallback and comparison
EVALUATEROW( "Missing is blank", ISBLANK(BLANK()), "Zero is blank", ISBLANK(0), "Loose equality", BLANK() = 0, "Strict equality", BLANK() == 0, "Fallback", COALESCE(BLANK(), 99), "Keep zero", COALESCE(0, 99), "Status", IF(ISBLANK(BLANK()), "Unknown", "Reported"), "Invalid number", IFERROR(VALUE("oops"), BLANK()))Expected in column order: TRUE, FALSE, TRUE, FALSE, 99, 0, Unknown, BLANK. = can coerce blanks for comparison; == does not equate blank and zero. ISBLANK states the intent explicitly. COALESCE chooses the first nonblank expression, not the first positive number. IFERROR handles an evaluation error; VALUE converts numeric text, discussed next. The final example is a controlled scalar demonstration, not a recommendation to hide malformed production inputs.
Choose a meaningful fallback
Use an omitted IF false branch only when BLANK is the intended result. A fallback of zero can make a missing observation look valid and change later averages. A data-quality flag and rejected-record table are generally more useful than suppressing a conversion failure. Use &&, || or NOT to combine conditions; parentheses clarify the business rule. For a measure with a possibly zero denominator, prefer DIVIDE rather than relying on error handling. DirectQuery calculated columns and RLS have function-specific restrictions; these examples are Import only.
Practice — Audit threshold boundaries
Without opening Desktop, classify BLANK, 0, 49, 50, 99 and 100 under the rule above. Count the bands in the fixture. Explain what changes if Amount = 0 is the first branch, and whether a missing value should become a zero. Record the original revenue column separately from the band. Then proceed to text conversion.