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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
JcROXford
New Member

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.