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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

Calculate sum of column in powerquery

Hi,

 

I would like to create the sum of a value column in PowerQuery. The value column is formatted as a number (decimals).

 

I thought this info would do the trick:

Solved: Calculate sum of column in query editor - Microsoft Power BI Community

However, the formula "List.Sum([Value])" gives me the following error:

"Expression.Error: We cannot convert the value 1 to type List.
Details:
Value=1
Type=[Type]"

I also tried the following formula "List.Sum(#"Changed Type"[Value])"  (as mentioned in the link above but I am not sure what the "changed type" part does here) but that formula give me the following error: 
"Expression.Error: The name 'Changed Type' wasn't recognized. Make sure it's spelled correctly."

What am I doing wrong here? How can I create a new column which displays the total sum of the value column next to my current data (but that keeps all my rows in the table the same).

 

Thank you for your help!

4 REPLIES 4
Syndicate_Admin
Administrator
Administrator

Thanks for sharing, it helped me the first time I tried it.

Greg_Deckler
Super User
Super User

@Anonymous Try:

 

List.Sum(Table.Column(#"PreviousRow", "Value"))

#"PreviousRow" is the step in your query you want to reference. If the column is Value, then use "Value", otherwise use the name of your column as text like "Column1".

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

This seems part of the solution, but it is not the entire solution yet.
My formula I used with the above feedback is:
= List.Sum(Table.Column(#"Changed Type1", "Value"))
(Changed Type 1 is my previous step in powerquery)

This makes all my rows and all my columns disappear and only the number (238) is displayed.  This is the right number, but I need to have it displayed in a new seperate column in my table where on each row of that new column the number 238 is displayed. 

Thank you for your feedback!

Hi, @Anonymous 

How did you add the custom column?

Please select feature 'custom column' then add the code as below:

186.png

Sample (M code):

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyagkkzMGkOJi3ApCWYNDRQio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Value", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each List.Sum(Table.Column(#"Changed Type", "Value")))
in
    #"Added Custom"

 

Best Regards,
Community Support Team _ Eason

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Kudoed Authors