Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 47

Sales Variance Analysis

Recommended resources

Hello! Welcome back to our project on Target vs. Actual analysis.

In the last lesson, you tackled the critical challenge of data granularity. By creating the [Allocated Budget] measure, you skillfully transformed our monthly targets into daily benchmarks, allowing for a true "apples-to-apples" comparison with our daily sales data.

Now that our actuals and targets are aligned, we can move on to the core of our analysis. This lesson is all about quantifying the difference between what we planned to happen and what actually happened. We will write the DAX measures that every stakeholder wants to see: the variance.

By the end of this 60-minute lesson, you will be able to write robust DAX measures to calculate both the absolute variance (the raw value difference) and the percentage variance between your sales and targets.

Why Both Absolute and Percentage Variance Matter

Imagine a manager tells you, "We were over budget by $10,000 this month." Is that good or bad news? It depends entirely on the context.

  • A $10,000 variance on a $20,000 target is a massive 50% over-performance.
  • A $10,000 variance on a $2,000,000 target is a minor 0.5% fluctuation.

This is why a professional analyst always provides both:

  • Absolute Variance: The raw number (e.g., +$10,000). It tells you the magnitude.
  • Percentage Variance: The relative number (e.g., +50%). It tells you the significance.

Let's start by building these essential calculations.


Step 1: The Foundation - Measure Branching

A best practice in DAX is called "measure branching." Instead of writing one enormous, complex formula, you build simple, reusable base measures and then reference them to create more complex calculations. This makes your code easier to read, debug, and manage.

We've already started this process. You have:

  1. A base measure for actual sales (e.g., Total Sales = SUM(Sales[SalesAmount])).
  2. A base measure for our daily target: [Allocated Budget].

Now, we'll use these two "branches" to create our variance measures. The following article provides an excellent guide on this approach.

How to Calculate Variance Percentage in Power BI

The article 'How to Calculate Variance Percentage in Power BI' from The Bricks clearly explains the step-by-step process of building variance measures, emphasizing the importance of base measures and safe division.

Please read the sections 'Step 1: Create Your Base Measures', 'Step 2: Calculate the Absolute Variance', and 'Step 3: Calculate the Variance Percentage'. Focus on how each new measure builds upon the previous one.


Step 2: Calculating Absolute Variance

As you saw in the article, calculating the absolute variance is straightforward. It's the simple difference between our actuals and our target.

In your Power BI file, create a new measure. We will use the base measures you already have.

Sales Variance (Abs) = [Total Sales] - [Allocated Budget]

This measure gives you the direct monetary value of how much you were over or under your allocated budget for any given period (day, month, quarter, etc.). A positive number means you exceeded the target; a negative number means you fell short.


Step 3: Calculating Percentage Variance with DIVIDE()

Next, we'll calculate the percentage variance to understand the relative significance of that absolute variance. The mathematical formula is:

(Actual - Target) / Target

We can write this in DAX by referencing our existing measures:

[Sales Variance (Abs)] / [Allocated Budget]

However, what happens if the budget for a certain period is zero or blank? The calculation would try to divide by zero, which results in an error and can break your visuals. This is unprofessional and should always be avoided.

The solution is to use the DIVIDE() function, which is designed to handle these scenarios gracefully.

The Syntax: DIVIDE(numerator, denominator, [alternate_result])

  • If the denominator is not zero, it performs the division.
  • If the denominator is zero, it returns the [alternate_result]. If you omit the alternate result, it returns BLANK(), which is often exactly what you want.

Let's create the final, robust measure for percentage variance.

Sales Variance (%) = 
DIVIDE(
    [Sales Variance (Abs)], 
    [Allocated Budget]
)

By creating this measure, you have a professional-grade calculation that won't break your report.


Alternative Demonstration

To see these concepts applied in a video format, you can watch this segment. The presenter quickly builds the data model and then creates the same types of variance measures.

Budget Vs. Actual Variance Analysis: Data Modeling, DAX, or Worksheet Formulas? 365 MECS Class 19

In the video 'Budget Vs. Actual Variance Analysis' from the excelisfun channel, the presenter demonstrates a complete workflow. Pay close attention to the moment he creates the variance measures.

Watch the segment from 08:30 to 09:35. Notice how he first creates the base measures for 'budgeted sales' and 'actual sales', and then uses them to create the 'variation' (absolute) and 'percent variation' measures, just like we did.


Your Turn: Visualize the Results

Now that you have the calculations, let's bring them to life on the report canvas.

  1. Open your Power BI report.
  2. Add a Matrix visual to the page.
  3. Configure the visual:
    • Rows: Drag DimDate[Year] and DimDate[MonthName] from your date table.
    • Values: Add the following measures in this order:
      • [Total Sales]
      • [Allocated Budget]
      • [Sales Variance (Abs)]
      • [Sales Variance (%)]
  4. Format the Percentage: With the Matrix selected, find the [Sales Variance (%)] measure in the Data pane. Click on it, then go to the Measure tools tab in the ribbon at the top and change the format from 'General' to 'Percentage'.

Your final table should look something like this, clearly showing the performance for each period.

Power BI Table Visual: Budget vs. Actual Sales Analysis
This image shows a completed Budget vs. Actual table in Power BI. Notice how the absolute variance ('Bud vs Act') and percentage variance ('Bud vs Act %') columns provide clear, actionable insights next to the base sales and budget figures.

Conclusion

Excellent work! You have successfully translated a core business requirement—understanding performance against a target—into robust and meaningful DAX measures. This is a fundamental skill for any data analyst.

Key Takeaways:

  • Absolute vs. Percentage: Absolute variance gives you the scale of the difference, while percentage variance gives you the context and significance.
  • Measure Branching: Building simple measures first (Total Sales, Allocated Budget) and then combining them into more complex ones (Sales Variance (Abs), Sales Variance (%)) is a key best practice for clean and maintainable DAX.
  • Safe Division: Always use the DIVIDE() function for ratios and percentages to prevent division-by-zero errors and create professional, error-free reports.

Preview of the Next Lesson:

Your table of numbers is powerful, but we can make it even more intuitive. What if you could instantly see "good" months in green and "bad" months in red? In our next lesson, you will write a conditional measure that returns a status like 'On Target' or 'Below Target', which is the first step toward creating dynamic, visually striking KPIs and conditional formatting.