Skip to content
ALLURE
Skip to main content

Allure Analytics

Best Practices in Power BI

Power Bi Best Practices Cover

Create explicit DAX measures

Power BI can aggregate a numeric column directly in a visual. This is an implicit measure. An explicit measure is a named DAX expression that you create and reuse throughout the model. Define explicit measures even for common aggregations such as SUM, MIN, MAX and AVERAGE. When business logic changes, updating a shared base measure updates the calculations that reference it. In the Fields or Data pane, numeric columns commonly show a sigma symbol (∑), while explicit measures show a calculator icon.

Numeric columns and explicit DAX measures in the original model.
Numeric columns and explicit DAX measures in the original model.

Hide technical numeric columns from report authors when they should be consumed through explicit measures. Keep useful attributes, such as Year or Month Number, available where they serve a reporting purpose.


Use DIVIDE when the denominator can be zero or BLANK

DAX supports both the division operator (/) and the DIVIDE function. Choose the approach that matches the possible values of the denominator.

Prefer DIVIDE when the denominator is an expression that can return zero or BLANK. Its default alternate result is BLANK, which usually communicates an undefined ratio more clearly than zero.

Division results when the denominator is zero or blank.
Division results when the denominator is zero or blank.

Not recommended

Profit Margin = [Profit] /[Sales]

Recommended

Profit Margin = DIVIDE([Profit], [Sales])

The following source example deliberately replaces a missing sales value with zero. Consider the reporting consequences before applying this pattern.

Sales (Blank to 0) =
IF(
    ISBLANK([Sales]),
    0,
[Sales]
)

Choose an alternate result intentionally. For many analytical measures, BLANK is the more useful result when no meaningful ratio can be calculated.

By default, visuals generally omit groups whose measures are all BLANK. Preserving BLANK can therefore keep a visual focused on customers, products or periods that have relevant data.

Return BLANK when the business meaning is “no meaningful result,” rather than automatically treating missing data as zero.

The next example places Profit Margin in a table grouped by customer.

The table includes customers without meaningful sales ratios.
The table includes customers without meaningful sales ratios.

The source model contains 18,484 customers. Because the original measure returns a value for customers without sales, the table attempts to show those customers too. This adds rows without adding useful information.

Large result sets can also trigger visual data-reduction behaviour, which may limit or summarize the information displayed.

The revised measure returns a ratio only when the denominator supports a meaningful calculation.

Recommended

Profit Margin = DIVIDE([Profit], [Sales])
The improved measure keeps the customer table focused.
The improved measure keeps the customer table focused.

The result is a more focused table: customers with no meaningful sales ratio are represented by BLANK rather than a fabricated zero.

The next expression checks explicitly for a blank or zero denominator before dividing. It illustrates the additional branching required when those checks are written manually.

Profit Margin (No Blank and zero) =
IF(
    OR(
        ISBLANK([Sales]),
        [Sales] == 0
    ),
    BLANK(),
    [Profit] / [Sales]
)

DIVIDE expresses this safe-division pattern more directly.

Recommended

Profit Margin = DIVIDE([Profit], [Sales])

Import the columns required by the model and reports. Remove unnecessary columns as early as practical; removing them only after loading does not avoid their import cost. Where data arrives in repeated period columns, consider unpivoting it to a consistent transaction or period grain. Prefer a model shape that supports clear relationships and efficient storage. Build reliable dimension tables from governed source data or carefully prepared, deduplicated queries. Star Schema. Create Measure’s Table.

Prefer a clear star schema

Separate dimensions from facts and use consistent keys and grain. A star schema is a useful default, although more complex models can contain several fact tables. Use measures for calculations that must respond to filter context; use calculated columns only when a stored row-level attribute is needed. Organize measures in dedicated tables and display folders. For a governed model, manage the date table and relationships deliberately instead of relying on automatic defaults. Choose visual interactions to fit the report. Use visual-level filters where they are appropriate, while keeping reusable business rules in shared model logic rather than duplicating them across many visuals.


Use SWITCH to simplify multi-branch logic

A long chain of nested IF expressions can be difficult to read and maintain.

The original nested IF colour expression and its result.
The original nested IF colour expression and its result.

Expression transcribed from the original illustration

Back Color = IF(
    SELECTEDVALUE(DimCustomer[EnglishEducation])="Bachelors",
    "Green",
    IF(
        SELECTEDVALUE(DimCustomer[EnglishEducation])="High School",
        "Red",
        IF(
            SELECTEDVALUE(DimCustomer[EnglishEducation])="Partial High School",
            "Tan",
            "White")
        )
    )

The SWITCH version makes the alternatives easier to scan and includes an additional Graduate Degree → Yellow branch.

The SWITCH colour expression, including the Graduate Degree branch.
The SWITCH colour expression, including the Graduate Degree branch.

Expression transcribed from the original illustration

Back Color =
SWITCH(
    SELECTEDVALUE(DimCustomer[EnglishEducation]),
    "Bachelors","Green",
    "High School","Red",
    "Partial High School","Tan",
    "Graduate Degree","Yellow",
    "White"
)

Keep SWITCH expressions concise and remove unnecessary repeated work.

The original editor demonstration uses Ctrl + Shift + L after selecting text to select matching occurrences and edit them together. Confirm the shortcut in the editor you are using.

The original animation simplifies repeated SWITCH conditions.
The original animation simplifies repeated SWITCH conditions.

Original animation — before

Example 1 bad =
SWITCH(
    TRUE(),
    'Date'[MonthNumber] = 1, "J",
    'Date'[MonthNumber] = 2, "F",
    'Date'[MonthNumber] = 3, "M",
    'Date'[MonthNumber] = 4, "A",
    'Date'[MonthNumber] = 5, "M ",
    'Date'[MonthNumber] = 6, "J ",
    'Date'[MonthNumber] = 7, "J ",
    'Date'[MonthNumber] = 8, "A ",
    'Date'[MonthNumber] = 9, "S",
    'Date'[MonthNumber] = 10, "O",
    'Date'[MonthNumber] = 11, "N",
    'Date'[MonthNumber] = 12, "D"
)

Original animation — after

Example 1 good =
SWITCH(
    'Date'[MonthNumber],
    1, "J",
    2, "F",
    3, "M",
    4, "A",
    5, "M ",
    6, "J ",
    7, "J ",
    8, "A ",
    9, "S",
    10, "O",
    11, "N",
    12, "D"
)