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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
Anonymous
Not applicable

Formula to sum columns based on criteria in another table

I am trying to use Power Query to add a new column with a formula that sums the values in a row from only a subset of the columns within the table. This subset of columns is based on yes or no criteria defined in another table. For example:

 

Table 1

a |  b |  c  

1 | 2 | 3

 

Table 2

Category | Include? (Yes or No)

a | N

b | Y

c | Y

 

Ideal Table Outcome

a | b | c | Sum (of only Yes Categories)

1 | 2 | 3 | (=2+3) 5

 

This example is very simple but gets complex when multiple categories are listed in my second table and incoming data within the first table will contain variable column categories. Is there a way to do this with Power Query or is there a better approach to this?

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

=let a=Table.SelectRows(Table2,each [#"Include?"]="Y")[Category] in Table.AddColumn(Table1,"SumOfSelectedColumns",each List.Sum(Record.ToList(Record.SelectFields(_,a,1))))

View solution in original post

3 REPLIES 3
wdx223_Daniel
Super User
Super User

=let a=Table.SelectRows(Table2,each [#"Include?"]="Y")[Category] in Table.AddColumn(Table1,"SumOfSelectedColumns",each List.Sum(Record.ToList(Record.SelectFields(_,a,1))))

Anonymous
Not applicable

Thank you so much! I created a new blank query with this formula and it worked perfectly (once adjusting for my unique column titles).

 

As a follow-up, do you know if I can add a step in Power Query to format the columns that were summed (e.g. in the output table, the column headers would be filled in a different color)? This may be a useful way to visually double-check which columns were totaled. 

Power Query can not define visual format, it's only a query tool

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors