Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
jjbates
Regular Visitor

SUMIF in Query Editor on Power BI Desktop?

I am trying to do a simple sumif in the Query Editor of the PowerBI desktop. I cannot edit the source data, so I need a calculated column as a new column that simply sums one column if it matches the values in another. I have done this with DAX before in Power Excel using this formula: CALCULATE(SUM([Received Qty]),FILTER('sheet 1',[Location]=EARLIER([Location])

 

and need something similar in the M language. Does this exist? Please help.

 

1 ACCEPTED SOLUTION
v-qiuyu-msft
Community Support
Community Support

Hi @jjbates,

 

You can open Query Editor, use Group By feature:

 

q3.PNG

 

The backend M formula is below:

 

= Table.Group(dbo_DimSalesTerritory, {"SalesTerritoryGroup"}, {{"Total", each List.Sum([SalesTerritoryKey]), type number}})

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

All the solutions I find point to doing a "Group By" in power query. However, there are many situations where every row is unique, but they often share a common identifier that needs a sum-if. For example, I can have a list of employees (All Unique). Each employee has a wage and a department. I want my end result to show the sum of wages related to the department as a percent. I don't want to group on department, because I will not be able to see the employee with their percentage of earnings as it relates to the department. A simple sum-if would easily do this. Does anyone have a working solution?  See table below. That's the output I'm looking for from Power Query.

 

EmployeeDepartmetn Wages  Department Wages % of Department
CharlesSales  50,000.00                150,000.0033%
KristiSales  40,000.00                150,000.0027%
MarySales  60,000.00                150,000.0040%
BobService  65,000.00                194,000.0034%
BillService  62,000.00                194,000.0032%
IsaacService  67,000.00                194,000.0035%
CharlesParts  87,000.00                269,000.0032%
WendyParts  45,000.00                269,000.0017%
SamParts  73,000.00                269,000.0027%
AaronParts  64,000.00                269,000.0024%
WayneFinance  84,000.00                180,000.0047%
JodiFinance  53,000.00                180,000.0029%
JamesFinance  43,000.00                180,000.0024%
v-qiuyu-msft
Community Support
Community Support

Hi @jjbates,

 

You can open Query Editor, use Group By feature:

 

q3.PNG

 

The backend M formula is below:

 

= Table.Group(dbo_DimSalesTerritory, {"SalesTerritoryGroup"}, {{"Total", each List.Sum([SalesTerritoryKey]), type number}})

 

Best Regards,
Qiuyun Yu

Community Support Team _ Qiuyun Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
MarcelBeug
Community Champion
Community Champion

For example the sum of all values where Group = "A":

= List.Sum(Table.SelectRows(PreviousStep, each [Group]="A")[Value])

 

Specializing in Power Query Formula Language (M)

Hello Marcel,

 

I am trying your formula but I cannot get it to work.


I am doing something a little more complicated:

 

= Table.Group(#"Removed Errors", {"order no."}, {{"Adj Gross Value", List.Sum(Table.SelectRows(PreviousStep, each Text.Start([ReferenceID], 3) = "ADJ") [Gross Value]), type number}}

 

As you can see I want to match using Text.Start but I cannot get it to work. This is my error:

 

Expression.Error: The name 'PreviousStep' wasn't recognized. Make sure it's spelled correctly.

 

If you can help thanks in advance.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.