• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Fixing Incorrect Totals in DAX

You are here: Home / Power BI / Fixing Incorrect Totals in DAX
fixing incorrect totals in dax
January 20, 2022 by Philip Treacy

Typically in Power BI visuals like a matrix or a table, and in pivot tables in Excel, we expect the totals to be the sums of the individual rows. This is probably because we are so used to adding up columns in Excel.

In this example image (below) I've written a measure called [Target] to indicate with a 1, months where my target has been met. As you can see there are 7 months that meet that target. You probably expect the 2012 total to be the sum of the values for each month in 2012, but as you can see, that isn't the case.

dax showing incorrect totals

I'm going to look at why this is and show you how to get your totals adding up as you want them to.

This Works In Power BI and Power Pivot in Excel

The issue I explain here and the solution to it, applies to both Power BI and Power Pivot (Pivot Tables) in Excel. I am using Power BI in my example.

Watch the Video

Subscribe YouTube

Download Power BI File

Enter your email address below to download the sample workbook.

By submitting your email address you agree that we can email you our Excel newsletter.
Please enter a valid email address.

Download Sample PBIX File


Sample Data Setup

I'm using data from Microsoft's Adventure Works sample database. Here's a snapshot of what the data looks like

sample data

I've also got a basic Date Table

DAX Date table

with a relationship between the two tables like this

relationship between tables

Measuring Monthly Targets

Lets say I want to look at months where I've met a particular target. I want to check how many months where the TotalDue is greater than $3,000,000.

I've written a measure called [Total Amount] which is

Total Amount = SUM ( 'Sales'[TotalDue] )

I create a new measure called [Monthly Target Met]

Monthly Target Met = IF ( [Total Amount] > 3000000, 1 )

What I want to do is check the [Total Amount] for each month and if it exceeds $3,000,000 then give me a 1. I can then count up all the 1's to get a total for the number of months in the year that exceeded the target.

After adding this measure to my matrix I get this

DAX measure showing incorrect totals

In 2012, there are 7 months that exceeded $3,000,000 but the total row for 2012 shows 1, not 7. Why is this?

Let's look at the DAX I wrote. I've said that if [Total Amount] is > 3000000 then give me a 1. The key here is to remember the filter context for the measure.

Monthly Target Met = IF ( [Total Amount] > 3000000, 1 )

The measure is worked out subject to the filter context for the cell that the measure is in.

Looking at the matrix, the monthly cells have a filter context that says, only check the total amount for that month.

Looking at the yearly totals the filter context here says check the [Total Amount] for that year. It's not saying check the Total Amount for each month in that year. This is where our intuition trips us up.

We expect it to be checking each month in the year because that was the intention of our measure, to check for months over $3,000,000.

However, all it's doing is checking the [Total Amount] for the cell it's in in the matrix, subject to that cell's filter context.

If we want the totals to count the number of months within the year that exceed our target then we need to use the iterator SUMX to check each month and count the ones that exceed $3,000,000.

So back to our measure. Using SUMX, it requires a table as its first argument and that table will be the 'DateTable'[Month Year] column because I want to work out the sum at the granularity of month in each year.

SUMX's 2nd argument is the expression to evaluate and that is the same IF I started with. The measure now looks like this

Monthly Target Met =
SUMX (
VALUES ( 'DateTable'[Month Year] ),
IF ( [Total Amount] > 3000000, 1 )
)

Checking the matrix, you can see that the totals are now adding up to the number of months within that year that exceed $3,000,000.

DAX measure showing correct totals

The measure still works for each individual month too because SUMX is only checking/counting that month (due to the filter context)

TIP : Check What a Table Function Creates

I've used the VALUES function to pass in the [Month Year] column from the Date Table. As with any function that creates a table (like FILTER) you can see exactly what it is creating by using the function code to actually create a new table.

To do this, from the Modeling tab click on New table

add new table

Paste in the code that creates the table

Table = VALUES ( 'DateTable'[Month Year] )

Check the new table in the Data view

table created by values function

Checking Daily Targets

Checking for a daily target uses a very similar approach to the monthly target, but because I want to check [Total Amount] at the day level rather than the month level, I need to change the dates used by SUMX to do its calculation.

I'll call the new measure [Daily Target Met] and this is the code

Daily Target Met =
SUMX (
'DateTable' ),
IF ( [Total Amount] > 25000, 1 )
)

I'm passing in the entire Date Table as the first argument to SUMX because I want it to check the [Total Amount] for every date.

For the daily target, I'm checking for days where [Total Amount] exceeds $25,000.

After adding the new measure to my matrix I get this

daily target met

I don't have dates added in the rows of the matrix but the measure is working because it iterates over every date. For example in June 2011 it checks all 30 days and counts 4 days where the [Total Amount] exceeds $25,000.

I can add the dates to the matrix rows

add dates to matrix rows

I can now see each individual date and confirm that the measure is working as I expect.

daily targets

fixing incorrect totals in dax

More Dax Posts

Introduction to DAX

Introduction to DAX Measures

Introduction to DAX in Power BI and Excel. Where and how to write DAX measures, understanding filter context and more.

More Pivot Tables Posts

automating and emailing pivot table reports

Automating and Emailing Pivot Table Reports

Automate the creation and distribution of pivot table reports with some VBA. Send reports to multiple email recipients using Outlook.
excel pivot table group data

Excel PivotTable Group Data [Video]

How to group data like dates into years, quarters or months, and ages into groups. Video instructions and sample workbook to download.
Excel PivotTables Unique Count 3 Ways

Excel PivotTables Unique Count 3 Ways

Excel PivotTables Unique Count, or distinct count as it's also know, is easy, but there are different approaches depending on your version of Excel.

More Power BI Posts

custom tooltips in power bi

Custom Tooltips in Power BI

Create custom tooltips for Power BI visuals. Use charts, images, numeric or categorical data to enhance the information your visuals convey
conditional formatting tables and matrices in power bi

Conditional Formatting in Power BI Tables and Matrices

How to apply conditional formatting to tables and matrices in Power BI. Use color, icons, data bars and URL's.
dax editor keyboard shortcuts

DAX Editor Keyboard Shortcuts

Keyboard shortcuts for the DAX editor in Power BI. Learning DAX is hard enough. Make your life easier by using these keyboard shortcuts.
fixing incorrect totals in dax

Fixing Incorrect Totals in DAX

If you're getting incorrect totals in your DAX measures, this post explains how to fix them. VIDEO and Sample file to download.
highlighting data in power bi visuals

Highlighting Data in Power BI Visuals

Learn several techniques to highlight or label important data points in your Power BI visuals. Sample file and code to download.
Power BI Organizational Data Types

Power BI Organizational Data Types in Excel

Power BI Organizational Data Types in Excel revolutionize the way we store and access our data with one central location and small files.
shape maps in power bi

Shape Maps in Power BI

Shape maps in Power BI can be used to show the distribution of a variable across geographic regions. Learn a trick to plot discrete data too.
static data tables

Static Tables in Power Query, Power Pivot and Power BI

Use static tables to store data in Power Query, Power Pivot and Power BI without needing to load data from an external source

Converting Decimal Time to Days, Hours, Minutes, Seconds in Power BI

Convert times and durations from decimal numbers to easily understood formats like hh:mm:ss. Sample code and file to download.
Power BI Dashboards

How to Build Power BI Dashboards

This video tutorial takes you step by step through building Power BI dashboards and reports, including publishing and sharing.


Category: Power BITag: dax, pivot tables
Previous Post:Introduction to DAXIntroduction to DAX Measures
Next Post:Excel Charts with Shapes for Infographics

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Current ye@r *

Leave this field empty

Sidebar

More results...

Featured Content

  • 10 Common Excel Mistakes to Avoid
  • Top Excel Functions for Data Analysts
  • Secrets to Building Excel Dashboards in Less Than 15 Minutes
  • Pro Excel Formula Writing Tips
  • Hidden Excel Double-Click Shortcuts
  • Top 10 Intermediate Excel Functions
  • 5 Pro Excel Dashboard Design Tips
  • 5 Excel SUM Function Tricks
  • 239 Excel Keyboard Shortcuts

100 Excel Tips and Tricks eBook

Download Free Tips & Tricks

Subscribe to Our Newsletter

Receive weekly tutorials on Excel, Power Query, Power Pivot, Power BI and More.

We respect your email privacy

Guides and Resources

  • Excel Keyboard Shortcuts
  • Excel Functions
  • Excel Formulas
  • Excel Custom Number Formatting
  • ALT Codes
  • Pivot Tables
  • VLOOKUP
  • VBA
  • Excel Userforms
  • Free Downloads

239 Excel Keyboard Shortcuts

Download Free PDF

Free Webinars

Excel Dashboards Webinar

Watch our free webinars and learn to create Interactive Dashboard Reports in Excel or Power BI

Click Here to Watch Now

mynda treacy microsoft mvpHi, I'm Mynda Treacy and I run MOTH with my husband, Phil. Through our blog, webinars, YouTube channel and courses we hope we can help you learn Excel, Power Pivot and DAX, Power Query, Power BI, and Excel Dashboards.

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk – For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.