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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

How to sum Columns based on list in power query

I want to consolidate monthly paysheets generated from SAP every month for different offices. The problem  with the  paysheets  is that it has many redundant columns which  needs to be added  and transformed into  a new column.  

 

To solve this problem I prepared One List of all columns reflecting in the consolidated paysheet after combine.  And seperate columns list to sum the columns e.g. OutOfAccount (used in the below query). 

 

Then using the List.Intersect function I removed the column names which are not in the All Column list and present in the OutOfAccount  list.

Then used following query to sum the columns available in the OutOfAccount List.

 

  Table.AddColumn(#"Removed Columns1","OutOfAccount", each List.Sum(Record.FieldValues(Record.SelectFields(_,OutOfAccount))), type number)

 

The query is useful for two to three columns but when I use it for more than 3 column names , the query is taking too much time. Please suggest an alternate solution.

 

This is the Paysheet -  https://1drv.ms/x/s!Al5DdavRiT-Ug60OeI4gp93c63zHrQ

 

And this is the list of coumns which if present in the paysheet needs to be added together according to the Category and subsequently deleted -  https://1drv.ms/x/s!Al5DdavRiT-Ug60P_5IA7cg4ubn7vg 

13 REPLIES 13
lbendlin
Super User
Super User

Can you provide a mapping table from all original columns to desired buckets?

Anonymous
Not applicable

This is the all columns mapping file.

 

https://1drv.ms/x/s!Al5DdavRiT-Ug65fMWkMAh1D_ymvEw 

Columns:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("rZrvbuO4EcBfhQhQIAE2znaBXtGPtmQ7BpLYa/u6H66HAy3RMW9l0qAkJ36be5Y+WYekJFP8Iym7/XC3Eec35IjkDIcj//bbzTeS7bEgaFayFEWcFYLuyoJydvOplt38/gk4XBCBogMWryRHa5LwMxEXgJ5oQlgOHZAazA+UvaJxlr2NQL45kYTiTD7zN8wSh9KtaCwEwQIU9B95hYkjijJeaDg9h3v8lYHRD+M85yCUL4A25S5PBAWNZVkgvkc4SXjJCoVvLyfyJqh8qapbu0VRMBtyJLBIv9B//2obcB3fRv0vtIU/81Jc+l7c5QB4huU5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gc30I1BXoHXYcGR0UaMG3GtDV4R0YLnppNFDWU+S7+WGGLrwB16HC8VxF/zAy0TXlwmy/hyyEfeFo5/i7KzWpQaZ9sOQ+va9PYW+Z7fkjq2DhF2j+mVNrPP8eCUOWRpdkswqEvlWwYPp6QkeI1qjZ3EtqK8znRIbD0rGS/mjhqLAiT5Yb5fx7DlwhXXhLvZa0I8E5EOFLOWBi4RwxiATCCcszTddQO5hKjMUYSGo+sGDN2k3FSCjVHUKQUi4TA0KR7hJpejfOCuJHL+qzPYfJKC6owxUB37w0bw2LYagcSbVh+1OjTbq/2FPxPd7Qh62cA++Xmo8jZqV31GuizNSn7iANypxGjzQLEXTtByhGU6o/P0BWKB203Smr9/R41g9Vk/zx426Uz9uqufptygKLOx8KlOzDT5T9prXp7tuNYEPXpulKYZBcaDSE0W9XhYNWVDIOdEjZmnWVzn1kP6FlBx4xZlciBEx+mzQGh1vY0MDuhUEbfH3jqp1B+y3YsJFqsv2HfWdCWel3L36X92Ci77lajPhznFOk/A3rkbsWcGJLE8G6kNDZN4uUxRl9Fh9V+2YlHEpnZXrrw36oqSblk3TtZQ6Xq7Rizz08DveqdSlg2WstEoNAQuqyn1dG2o/ayLNkF1O7OgPTKL6gyLE287PhC5753Ueh+soPbisL8G0KPV1sM6Fnd9OdMH9Fkhcp8P93QbSXA8ZDewxULHwkXdDpsnvXy5nj/n7/wA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Column Name" = _t, Category = _t]),
    #"Removed Duplicates" = Table.Distinct(Source, {"Column Name"})
in
    #"Removed Duplicates"

Paysheet:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("7ZdNcsMwCIXv4jXTAQECnSWT+1+juLUcxz8ZV1baTVfWZDRIeh88yO02kEoaYMAPxM2HCySc1hlylmlJ6XtRQNCnrZBxN8b5j0Y4l2sxLn7S1TeswgH+PCAlIKTGE6kAZdvqKQhMX7/f4TaYux1FkPIg6SCcVsyJoKB0g24CJP43tPMDzwyegM3ecJag1pMmOrvbHNi5lX0GI93KqhYYubJn5HJ8ySjoWRzPvmJfbaFDrVPk5h8Vea9al/JMKgqX5ce5Ex6R2p8AOFf7QlGONc3EVUo+ijDurDooMK+JGyjnbtQlDMXziX1APj3L6k28+k8UrdZwDSUv+fkCnS1/DZf0uXZsd18B5FYTJIWskyGrQKkHjs27+JwElg/bfF6UPSGkTd2TQORQtzTwEiZ7Ig3e8dEdzzfg3Gq6L8mAyYlGPgJsloMx5rIdXdWjGeRKv2jhQ0UWU4qDS02KGX5aGEuHhj9aSroWoxkI7tCPjGDtEp5BX6pju8dcbABe6S+F1ZjWLVX6Fun9T39Ie7XP4Npn3vt9+qxAVcylsJKqn3/RxySH9PFxaQd13dKnNL/vOn2NueQd0/WZ2t+jP07JfZzfN3/1LMhyzbyXKYBguTSeqxr9eg7/kDeCTqPH/f4J", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Employee Id" = _t, #"Dearness Allowance" = _t, #"DA on TpA" = _t, #"Subsistence Allw." = _t, #"Basic Pay" = _t, #"Dearness Allowance.1" = _t, #"DA on TpA.1" = _t, #"House Rent Allowance" = _t, #"Transport Allowance" = _t, #"Spl. Allowance" = _t, #"Cash Handling Allowance" = _t, #"Care Taking Allowance" = _t, #"Spl. Pay" = _t, #"Training Allowance" = _t, CEA = _t, #"Tour/TA Reimb." = _t, #"Split Duty Allw." = _t, #"Total Earnings" = _t, #"Dearness Allowance Arr." = _t, #"House Rent Allowance Arr." = _t, #"Transport Allowance Arr." = _t, #"DA on TpA Arr." = _t, #"Basic Pay Arrear" = _t, #"Dearness Allowance Arrear" = _t, #"Band Pay Arr." = _t, #"House Rent Allowance Arr..1" = _t, #"Transport Allowance Arr..1" = _t, #"Spl. Allowance Arrear" = _t, #"DA Arrears" = _t, #"HRA Arrear" = _t, #"DA on TpA Arrears" = _t, #"TA Arrears" = _t, #"Band Pay Arr..1" = _t, #"Total Arrears" = _t, #"GPF Subscription" = _t, #"Prof. Tax" = _t, #"Income Tax" = _t, #"Claim from previous month" = _t, #"BF NPS Arrears" = _t, #"CF PF Monthly" = _t, #"Ptax Deduction Carry fwd" = _t, #"House Rent Recovery" = _t, #"Court Attachment (ODFM)" = _t, #"Punishment Rec." = _t, #"License Fee" = _t, #"Audit office Rec" = _t, #"Cooperative Credit Soc Re" = _t, #"AOR Non Taxable" = _t, #"PLI Premium" = _t, #"Recreation Club subscript" = _t, #"Union/Association Subscri" = _t, #"Welfare Fund Contribution" = _t, Connections = _t, #"Other Societies" = _t, #"OMCA (R)" = _t, #"PC Adv. (R)" = _t, #"PC Adv. Interest (R)" = _t, #"HBA Principle (R)" = _t, #"HBA Interest (R)" = _t, #"GPF Adv. (R)" = _t, #"OMCA Interest (R)" = _t, #"Total Deductions" = _t, #"Total Gross Amount" = _t, #"Net Pay" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Employee Id"}, "Attribute", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Unpivoted Other Columns",".1","",Replacer.ReplaceText,{"Attribute"}),
    #"Renamed Columns" = Table.RenameColumns(#"Replaced Value",{{"Attribute", "Column"}}),
    #"Merged Queries" = Table.NestedJoin(#"Renamed Columns", {"Column"}, Columns, {"Column Name"}, "Columns", JoinKind.LeftOuter),
    #"Expanded Columns" = Table.ExpandTableColumn(#"Merged Queries", "Columns", {"Category"}, {"Category"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Expanded Columns",null,"Unmapped",Replacer.ReplaceValue,{"Category"})
in
    #"Replaced Value1"

 

Anonymous
Not applicable

Thanks a lot sir 🙏🙏

lbendlin
Super User
Super User

The column names don't match exactly.  For example the sheet says "Dearness Allowance"  but the lookup table says "Dearness Allowance Arr."  .  Are these the same columns?

Anonymous
Not applicable

Spoiler
 

No.   Not same. 

Please provide sanitized sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

Anonymous
Not applicable

This is the original paysheet, 

Employee IdDearness AllowanceDA on TpASubsistence Allw.Basic PayDearness AllowanceDA on TpAHouse Rent AllowanceTransport AllowanceSpl. AllowanceCash Handling AllowanceCare Taking AllowanceSpl. PayTraining AllowanceCEATour/TA Reimb.Split Duty Allw.Total EarningsDearness Allowance Arr.House Rent Allowance Arr.Transport Allowance Arr.DA on TpA Arr.Basic Pay ArrearDearness Allowance ArrearBand Pay Arr.House Rent Allowance Arr.Transport Allowance Arr.Spl. Allowance ArrearDA ArrearsHRA ArrearDA on TpA ArrearsTA ArrearsBand Pay Arr.Total ArrearsGPF SubscriptionProf. TaxIncome TaxClaim from previous monthBF NPS ArrearsCF PF MonthlyPtax Deduction Carry fwdHouse Rent RecoveryCourt Attachment (ODFM)Punishment Rec.License FeeAudit office RecCooperative Credit Soc ReAOR Non TaxablePLI PremiumRecreation Club subscriptUnion/Association SubscriWelfare Fund ContributionConnectionsOther SocietiesOMCA (R)PC Adv. (R)PC Adv. Interest (R)HBA Principle (R)HBA Interest (R)GPF Adv. (R)OMCA Interest (R)Total DeductionsTotal Gross AmountNet Pay
15420.000.000.0039,200.006,664.00612.009,408.003,600.000.000.000.000.000.000.000.000.0059,484.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.00200.000.000.000.000.000.000.000.000.000.000.002,000.000.000.000.000.000.000.0012,101.000.000.000.000.000.000.000.0019,167.0059,484.0040,317.00
78870.000.000.0049,600.008,432.00612.0011,904.003,600.000.000.000.000.000.000.000.000.0074,148.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.006,000.00200.001,377.000.000.000.000.000.000.000.000.000.000.000.00405.0020.0050.000.000.008,383.000.000.000.000.000.000.000.0016,715.0074,148.0057,433.00
30390.000.000.0040,400.006,868.00612.000.003,600.000.000.000.000.000.000.000.000.0051,480.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.00200.000.000.000.000.000.000.000.000.00493.000.0012,347.000.000.000.000.000.000.002,020.000.000.000.000.000.000.000.0020,067.0051,480.0031,413.00
54960.000.000.0031,400.005,338.00612.007,536.003,600.000.000.000.000.000.000.000.000.0048,486.000.000.000.000.004,187.00712.0082.001,005.00480.000.000.000.000.000.000.006,466.000.00200.000.000.000.000.000.000.000.000.000.000.000.000.002,152.000.0070.000.000.009,038.000.000.000.000.000.000.000.0015,654.0054,952.0039,298.00
57620.000.000.0060,400.0010,268.00612.0014,496.003,600.000.000.000.000.000.000.000.000.0089,376.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.005,000.00200.007,363.000.000.000.000.000.000.000.000.000.000.000.001,741.000.000.000.000.0015,676.000.000.000.000.000.000.000.0030,660.0089,376.0058,716.00
95930.000.000.0052,000.008,840.00612.0012,480.003,600.000.000.000.000.000.000.000.000.0077,532.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.0010,000.00200.005,035.000.000.000.000.000.000.000.000.000.003,500.000.000.000.0075.000.000.002,020.000.000.000.000.000.000.000.0020,860.0077,532.0056,672.00
73630.000.000.0052,000.008,840.00612.0012,480.003,600.000.000.000.000.000.000.000.000.0077,532.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.0025,000.00200.003,857.000.000.000.000.000.000.000.000.000.003,500.000.000.000.0075.000.000.002,020.000.000.000.000.000.000.000.0035,132.0077,532.0042,400.00
70240.000.000.0050,500.008,585.00612.0012,120.003,600.000.000.000.000.000.000.000.000.0075,417.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.000.0015,000.00200.004,143.000.000.000.000.000.000.000.000.000.008,000.000.007,023.0025.0075.000.000.0020,769.000.000.000.000.000.000.000.0055,265.0075,417.0020,152.00
Anonymous
Not applicable

I want to convert the paysheet in following format by summing up several columns,

 

Employee IdDearness AllowanceDA on TpASubsistence Allw.Basic PayDearness AllowanceDA on TpAHouse Rent AllowanceTransport AllowanceSpl. AllowanceArrearsOut Of AccountTotal Gross Pay Total RecoveryNet Pay
37550.000.000.0039,200.006,664.00612.009,408.003,600.000.00    40,317.00
58650.000.000.0049,600.008,432.00612.0011,904.003,600.000.00    57,433.00
72820.000.000.0040,400.006,868.00612.000.003,600.000.00    31,413.00
97330.000.000.0031,400.005,338.00612.007,536.003,600.000.00    39,298.00
62750.000.000.0060,400.0010,268.00612.0014,496.003,600.000.00    58,716.00
94800.000.000.0052,000.008,840.00612.0012,480.003,600.000.00    56,672.00
18760.000.000.0052,000.008,840.00612.0012,480.003,600.000.00    42,400.00
29710.000.000.0050,500.008,585.00612.0012,120.003,600.000.00    20,152.00
58700.000.000.0050,500.008,585.00612.0012,120.003,600.000.00    30,910.00
lbendlin
Super User
Super User

 it has many redundant columns which  needs to be added  and transformed into  a new column.

Right, but this may not need to be done in Power Query.  You might be able to get better performance by doing that in DAX.

 

Also, read about the difference between Table.RemoveColumns and Table.SelectColumns

Anonymous
Not applicable

Can you give me solution in Dax?

By redundant I meant that,  same category of amount.  I want to get these coumns added together and get rid of them. 

 

 I want to get these coumns added together and get rid of them

"premature optimization is the root of all evil"

 

Try loading the raw data first, and do the math in DAX. It runs in memory and is much faster than Power Query. Groupings in Power Query are very costly.

 

Please provide sanitized sample data that fully covers your issue. I can only help you with meaningful sample data.
Please paste the data into a table in your post or use one of the file services like OneDrive or Google Drive.
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...

Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Anonymous
Not applicable

Updated my first post with the file links.  Please check. 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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