Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
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!
Thanks for sharing, it helped me the first time I tried it.
@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".
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:
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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
89 | |
82 | |
53 | |
40 | |
35 |