Power BI SUMIF: How to Use CALCULATE and FILTER
In this article
To perform a "SUMIF" in Power BI, you use the CALCULATE function combined with the SUM function and a filter expression. Because Power BI uses DAX (Data Analysis Expressions) rather than cell-based formulas like Excel, you do not use a single SUMIF function; instead, you create a Measure that tells Power BI to sum a specific column while applying one or more filters to the data context. This allows you to calculate totals for specific categories, dates, or regions regardless of what other filters are applied to your report page.
What You'll Need
- A Power BI Desktop installation.
- A dataset loaded into your model with at least one numeric column (the value to sum) and one categorical column (the criteria to filter by).
- Basic access to the "Data" or "Report" view to create new measures.
Step-by-Step
- Identify your target columns: Before writing the formula, determine which column contains the numbers you want to add up (e.g.,
'Sales'[Amount]) and which column contains the criteria you want to filter by (e.g.,'Sales'[Region]). - Create a New Measure: In the Data pane on the right side of the screen, right-click the table where you want the calculation to live and select New measure. This opens the formula bar at the top of the canvas. Note that menu labels may differ slightly depending on your version of Power BI Desktop.
- Write the CALCULATE function: Start your formula by typing
CALCULATE(. The CALCULATE function is the engine of Power BI; it modifies the filter context of a calculation. - Define the Summation: Inside the CALCULATE parentheses, enter the SUM function. For example:
SUM('Sales'[Amount]). This tells Power BI what the final mathematical operation should be. - Apply the Filter Criteria: After a comma, define your condition. To mimic a SUMIF, you specify the column and the value it must match. For example, to sum only the "North" region, write:
'Sales'[Region] = "North". - Close the formula: Ensure you have closed all parentheses. Your complete formula should look like this:
Total North Sales = CALCULATE(SUM('Sales'[Amount]), 'Sales'[Region] = "North"). - Press Enter: Once you hit Enter, the measure is saved. You can now drag this measure into a Card visual, a Table, or a Bar Chart to see the conditional total.
- (Optional) Use the FILTER function for complex logic: If you need to filter based on a measure or a more complex expression (like "Sales greater than 100"), use the FILTER function inside CALCULATE. Example:
High Value Sales = CALCULATE(SUM('Sales'[Amount]), FILTER('Sales', 'Sales'[Amount] > 100)).
Common Mistakes
One of the most frequent errors is attempting to create a Calculated Column instead of a Measure. If you create a calculated column using a SUMIF-style formula, Power BI calculates the value for every single row in the table. This can lead to massive file sizes and incorrect totals when you drag that column into a visual, as Power BI will then sum the already-summed totals. Always use a Measure for conditional aggregations unless you specifically need the value to exist as a static attribute of the row.
Another common mistake is forgetting the quotes around text strings. In DAX, any text value used as a filter (like "North" or "Completed") must be enclosed in double quotes. If you omit them, Power BI will assume you are referring to another column or a measure name, resulting in a syntax error.
Users also often struggle with the "Filter Context." If you have a slicer on your page that filters for the "South" region, but your measure is hard-coded to sum the "North" region, the visual may show a blank result. This happens because the slicer and the measure are conflicting. To override the slicers on the page, you would need to wrap your filter in the ALL function, such as CALCULATE(SUM('Sales'[Amount]), ALL('Sales'[Region]), 'Sales'[Region] = "North").
Tips
To make your reports more maintainable, avoid hard-coding values inside your measures. Instead of creating five different measures for five different regions, create one general sum measure: Total Sales = SUM('Sales'[Amount]). Then, use a Slicer visual on your report page. The Slicer acts as the "IF" part of the SUMIF, allowing the user to dynamically change the criteria without you having to write new DAX code for every possibility.
If you need to sum based on multiple conditions (similar to SUMIFS in Excel), you can simply add more arguments to the CALCULATE function. Each comma-separated filter acts as an "AND" operator. For example: North High Value Sales = CALCULATE(SUM('Sales'[Amount]), 'Sales'[Region] = "North", 'Sales'[Status] = "Shipped"). This will only sum rows that meet both criteria.
For better performance in very large datasets, ensure the columns you are filtering are indexed or categorized correctly in the Data view. Using integers for filtering is generally faster than using long text strings, though for most standard business reports, the difference is negligible.
Troubleshooting
If your formula returns a blank value, first check your spelling and capitalization of the filter criteria. DAX is generally not case-sensitive for text comparisons, but trailing spaces in your data (e.g., "North " instead of "North") will cause the match to fail. Use the "Trim" function in Power Query to clean your data if you suspect hidden spaces.
If you receive a circular dependency error, it usually means you are trying to create a calculated column that refers to another column which in turn refers back to the first one. Moving your logic from a Calculated Column to a Measure almost always resolves this issue.
If the total is higher than expected, check if you have duplicate rows in your data. Since SUM adds every instance of a value, any duplicated records in your source table will be counted multiple times. Use the "Remove Duplicates" feature in the Power Query Editor to ensure your data is clean.
If the formula is returning an error stating that a single value cannot be determined, you are likely trying to use a column reference where a measure or an aggregated value is required. Ensure that the first argument of your CALCULATE function is an aggregation like SUM, AVERAGE, or COUNT, rather than just a raw column name.
Frequently Asked Questions
Can I use SUMIF with dates?
Yes. You can filter by a specific date using or use date functions like within the CALCULATE function to sum values for a specific year.
What is the difference between SUMIF in Excel and CALCULATE in Power BI?
Excel's SUMIF looks at a specific range of cells. Power BI's CALCULATE looks at the entire data model. While Excel is cell-centric, Power BI is filter-centric, meaning the result changes based on the visuals and slicers surrounding it.
How do I sum if a cell is NOT equal to a value?
Use the inequality operator <>. For example, CALCULATE(SUM('Sales'[Amount]), 'Sales'[Region] <> "North") will sum everything except the North region.
Can I use a SUMIF logic to count rows instead?
Yes. Simply replace the SUM() function with COUNT() or COUNTROWS(). For example: CALCULATE(COUNTROWS('Sales'), 'Sales'[Region] = "North") will give you the number of sales in the North region.
Can I reference another cell for the criteria?
In Power BI, you don't reference cells, but you can reference other measures. If you have a measure that captures a selected value, you can use that measure inside a FILTER function to create a dynamic SUMIF effect.