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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
AlexJones
New Member

Sum of month columns by year

Hello,

 

I'm new with power query and I try to do the sum of each month column by year.

 

For example, I have columns : jan. 2025, feb. 2025, ..., dec. 2025 and I want to sum all by row inside a 2025 column.

Same for 2026, 2027...

 

I tried this :

 

= List.Accumulate({Number.From(#"ParamYear")+1..2040}, #"Source", (state, current) => Table.AddColumn(state, Number.ToText(current), each List.Sum(List.Transform({"jan.", "feb.", "mar.", "apr.", "may", "june", "july", "aug.", "sept.", "oct.", "nov.", "dec."}, each Table.Column(state, _ & " " & Number.ToText(current))))))

 

 

I think I am close to the solution, I tried to implement this solution

 

Thanks you in advance,

 

Alex

1 ACCEPTED SOLUTION

I find a solution before I see your comment :

List.Accumulate({2022..2031}, #"Source", (state, current) => Table.AddColumn(state, Number.ToText(current), (record) => List.Sum(List.Transform({"jan.", "feb.", "mar.", "apr.", "may", "june", "july", "aug.", "sept.", "oct.", "nov.", "dec."}, (month) => Record.FieldOrDefault(record, month & " " & Number.ToText(current), 0)))))

It was easier by not using each _ but only lambda with specified arg name.

 

Thanks all !

 

View solution in original post

6 REPLIES 6
AlexJones
New Member

Example of the dataset :

AlexJones_0-1704804198407.png

If possible, I want also to be able to do the sum by year if a user delete a column like "mar. 2024", the sum need to be done on other existing columns

 

Wouldn't it make more sense to transform the table so that you had 4 Columns? ID, Month, Year and Value. It is easy to transform it this way and you can easily do data manipulations in Dax etc....  

Data come from an export of another software, I can't change the format. And there is a lot of other columns that are processed to generate the result.

Hello, @AlexJones first unpivot all columns but ID. Then

 - to get totals by mon. year: group by that column

 - to get totals by year: split "mon. year" column by space and group by new "year" column. 

I find a solution before I see your comment :

List.Accumulate({2022..2031}, #"Source", (state, current) => Table.AddColumn(state, Number.ToText(current), (record) => List.Sum(List.Transform({"jan.", "feb.", "mar.", "apr.", "may", "june", "july", "aug.", "sept.", "oct.", "nov.", "dec."}, (month) => Record.FieldOrDefault(record, month & " " & Number.ToText(current), 0)))))

It was easier by not using each _ but only lambda with specified arg name.

 

Thanks all !

 

zenisekd
Super User
Super User

Could you share a sample / printscreen of your dataset in PQ?

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.