List.Sum and List.Product together

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
8,120
Office Version
  1. 365
This should be simple, but I can't get the syntax right.

I have 5 columns in my data, each of which might contain null values:

Field A Values
Field A Percentages
Field B1 Values
Field B2 Values
Field B Percentages

I just want to add a new column that equals (Field A Values * Field A Percentages)+((-Field B1 Values + Field B2 Values)* Field B Percentages)

This is what I tried:

Code:
#"Add Values" = Table.AddColumn(#"(Previous Step Name)", "Calculation Result", each
List.Sum(
List.Product(
{[Field A Values],
[Field A Percentages]}
),
List.Product(
{[Field B Percentages],
List.Sum(
{-[Field B1 Values],
[Field B2 Values]}
)}
)
)
)

That compiles OK (no syntax errors detected), but it outputs "Error" in each row.

What's the *right* way to nest List.Sum and List.Product usages here?
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi Oaktree,

Maybe I misunderstand your query. But are your inputs on the row level? Then I believe these are not a list and you can write the formula like you did:
Field A Values * Field A Percentages)+((-Field B1 Values + Field B2 Values)* Field B Percentages.

Else doesn't your first List.Sum require a list input with curly brackets too?

Power Query:
"Add Values" = Table.AddColumn(#"(Previous Step Name)", "Calculation Result", each
List.Sum( {
List.Product(
{[Field A Values],
[Field A Percentages]}
),
List.Product(
{[Field B Percentages],
List.Sum(
{-[Field B1 Values],
[Field B2 Values]}
)}
)}
)
)
 
Upvote 0
Solution
Thank you! The issue was exactly the missing curly brackets on the outer List.Sum.
 
Upvote 0
Most welcome! Thanks for the feedback. Took a while before I spotted it :-)
 
Upvote 0

Forum statistics

Threads
1,223,707
Messages
6,174,000
Members
452,542
Latest member
Bricklin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top