Summarize selective columns in power query

sailepaty

New member
Joined
Mar 30, 2011
Messages
4
Reaction score
0
Points
0
Location
Dallas, TX
I created a custom column with the following formula.

= Table.AddColumn(#"Added Custom", "Custom", each [pP01]+[pP02]+[pP03]+[pP04]+[pP05]+[pP06])

Is there a way to pass the fields that I want to add? For example if I just want to add [pP02]+[pP03]

Something like this
= Table.AddColumn(#"Added Custom", "Custom", each [pP02]+[pP03])

Or like this
= Table.AddColumn(#"Added Custom", "Custom", each [pP01]*1+[pP02]*1+[pP03]*0+[pP04]*0+[pP05]*0+[pP06]*0)

Thanks in advance.
 
I posted same question in the following link

http: // www . mrexcel . com / forum / power-bi / 846491-summarize-selective-columns-power-query . html # post4120520

Thanks

PS. I had to insert spaces in the link because the forum didn’t allow me to post it as a link
 
Hi Herb, by looking your code I just learned how to use other tables rows without having to merge the tables. Base on that, the below code gives me what I'm looking for.

Code:
let
    tP = Excel.CurrentWorkbook(){[Name="TableP"]}[Content],
    SourceTable = Excel.CurrentWorkbook(){[Name="TableS"]}[Content],
    AddTotP = Table.AddColumn(SourceTable, "TotP", each [P01]*tP[v01]{0}+[P02]*tP[v02]{0}+[P03]*tP[v03]{0}+[P04]*tP[v04]{0}+[P05]*tP[v05]{0}),
    AddTotC = Table.AddColumn(AddTotP, "TotC", each [C01]*tP[v01]{0}+[C02]*tP[v02]{0}+[C03]*tP[v03]{0}+[C04]*tP[v04]{0}+[C05]*tP[v05]{0}),
    SelCols = Table.SelectColumns(AddTotC,{"name", "TotP", "TotC"})
in
    SelCols


Thanks for your help
 
Very elegant.
Mighty nice of you to list crossposts at other forums.
Now don't forget to do the same at the other forums.
 
Back
Top