<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: List.Sum throwing error Power Query in Power Query</title>
    <link>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1288687#M41002</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="109184" data-lia-user-login="smjzahid" class="lia-mention lia-mention-user"&gt;smjzahid&lt;/a&gt;&amp;nbsp;, is this what you are wanting, what is in the far right "custom" column?&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;If so, your formula should just be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;if [Units] = "Hours" then [Value] else null&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No need for List.Sum. Sorry if I've overcomplicated it. I used List.Sum to total&amp;nbsp;&lt;EM&gt;all rows&lt;/EM&gt; where Units = "Hours" which is why it is 10 for those for rows (1+2+3+4) and null for the kWh rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that still isn't what you need, please give us an example of what you expect. You can screenshot somethig from Excel to mock it up if you want, just explain the logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is what you want, then Power Query is the best place to do this. Power Query excels in this kind of transformation that is done for each record vs trying to access an entire table at a time per record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Aug 2020 21:13:02 GMT</pubDate>
    <dc:creator>edhans</dc:creator>
    <dc:date>2020-08-11T21:13:02Z</dc:date>
    <item>
      <title>List.Sum throwing error Power Query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1287329#M40965</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created a custom column named Units (derived from an existing column in the table). I want to create another calculated column which returns me the total for each row filtered by column Units.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;The M code for the custom column UNITS is below&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;= Table.AddColumn(#"Filtered Rows", "Units", each if Text.Contains([Metric], "tonnes") then "Tonnes" else if Text.Contains([Metric], "Petrol ") then "Petrol Litres" else if Text.Contains([Metric], "Hours") then "Hours" else if Text.Contains([Metric], "kWh") then "KWH" else if Text.Contains([Metric], "Tour") then "Tour" else if Text.Contains([Metric], "m3") then "Metric Cube m3" else if Text.Contains([Metric], "LPG") then "LPG Litres" else if Text.Contains([Metric], "Diesel ") then "Diesel Litres" else null)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Note: The datatype for column Value is DECIMAL NUMBER&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;for eg.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;if [Units] = "Hours" 
then List.Sum([VALUE])
else null&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Here is the snip of my table below&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;and the error returned is below&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 11:51:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1287329#M40965</guid>
      <dc:creator>smjzahid</dc:creator>
      <dc:date>2020-08-11T11:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: List.Sum throwing error Power Query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1287382#M40968</link>
      <description>&lt;P&gt;Why not do this in a DAX calculated column?&amp;nbsp; It would be easier.&amp;nbsp; However, your expression is trying to use the value in the current row of the [Value] column, which is why it can't convert it to a list.&amp;nbsp; To do what you are looking for, you will need something like this to filter the table from the previous step to just the rows for "Hours" and reference the [Value] column to get the list of values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;= List.Sum(Table.SelectRows(#"Previous Step", each [Units]="Hours")[Value])&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this works for you, please mark it as the solution.&amp;nbsp; Kudos are appreciated too.&amp;nbsp; Please let me know if not.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Pat&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 12:16:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1287382#M40968</guid>
      <dc:creator>mahoneypat</dc:creator>
      <dc:date>2020-08-11T12:16:42Z</dc:date>
    </item>
    <item>
      <title>Re: List.Sum throwing error Power Query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1288223#M40987</link>
      <description>&lt;P&gt;You have to reference the entire table, then specify the column, and the table is the previous step, which needs to be filtered.&lt;BR /&gt;The key formula is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;if [Units] = "Hours" then 
     List.Sum(
         Table.SelectRows(
             #"Changed Type",
             each [Units] = "Hours"
         )[Value]
     ) 
else null&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To see a full example of this use this M code below by pasting it into a blank query.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8sgvLSpW0lEyVIrVQfCMUHjGKDwTMC87PAOuC86OBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Units = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Value", type number}}),
    #"Add Total" = 
        Table.AddColumn(
            #"Changed Type",
            "Total",
            each
                if [Units] = "Hours" then 
                    List.Sum(
                        Table.SelectRows(
                            #"Changed Type",
                            each
                            [Units] = "Hours"
                        )[Value]) 
                else null
                        
        )
in
    #"Add Total"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will return the following new column called Total:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this &lt;I&gt;will&amp;nbsp;&lt;/I&gt;&lt;EM&gt;not&lt;/EM&gt; perform well on large data sets. Your better bet is to return the data to DAX and use a measure to return that information. You can use a calculated column, but those have issues of their own.&lt;BR /&gt;&lt;BR /&gt;But if you need it in Power Query, and your dataset isn't too large, this will work fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general, try to avoid calculated columns. There are times to use them, but it is rare. Getting data out of the source system, creating columns in Power Query, or DAX Measures are usually preferred to calculated columns. See these references:&lt;BR /&gt;&lt;A href="https://exceleratorbi.com.au/calculated-columns-vs-measures-dax/" target="_blank" rel="noopener"&gt;Calculated Columns vs Measures in DAX&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://www.sqlbi.com/articles/calculated-columns-and-measures-in-dax/" target="_blank" rel="noopener"&gt;Calculated Columns and Measures in DAX&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://www.sqlbi.com/articles/storage-differences-between-calculated-columns-and-calculated-tables//" target="_blank" rel="noopener"&gt;Storage differences between calculated columns and calculated tables&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) In Power Query, select New Source, then Blank Query&lt;BR /&gt;2) On the Home ribbon, select "Advanced Editor" button&lt;BR /&gt;3) Remove everything you see, then paste the M code I've given you in that box.&lt;BR /&gt;4) Press Done&lt;BR /&gt;5) &lt;A href="https://community.powerbi.com/t5/Community-Blog/Utilizing-M-Code-Samples-Given-as-Solutions-in-Power-Query/ba-p/1147514" target="_blank" rel="noopener"&gt;See this article if you need help using this M code in your model.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 16:47:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1288223#M40987</guid>
      <dc:creator>edhans</dc:creator>
      <dc:date>2020-08-11T16:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: List.Sum throwing error Power Query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1288561#M40998</link>
      <description>&lt;P&gt;Hi &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="24715" data-lia-user-login="edhans" class="lia-mention lia-mention-user"&gt;edhans&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your formual works, However it gives me a Grand Total summed up in all rows (the value is same for all row.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am expecting it to give me total row by row (similar to how SUMX and other iterator function works in DAX ).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is what I am getting is shown below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the result like column Value (see the red arrow)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 19:37:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1288561#M40998</guid>
      <dc:creator>smjzahid</dc:creator>
      <dc:date>2020-08-11T19:37:57Z</dc:date>
    </item>
    <item>
      <title>Re: List.Sum throwing error Power Query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1288606#M40999</link>
      <description>&lt;P&gt;I had an error in my first formula but edited it within 10min. Can you verify? Post your formula here if you are still getting the wrong value.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 20:02:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1288606#M40999</guid>
      <dc:creator>edhans</dc:creator>
      <dc:date>2020-08-11T20:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: List.Sum throwing error Power Query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1288636#M41001</link>
      <description>&lt;LI-CODE lang="markup"&gt;= Table.AddColumn(#"Changed Type", "Total Hours", each if [Units] = "Hours" 
then List.Sum(
    Table.SelectRows(
        #"Changed Type", each [Units] = "Hours")
        [VALUE])
        
else null)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 11 Aug 2020 20:31:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1288636#M41001</guid>
      <dc:creator>smjzahid</dc:creator>
      <dc:date>2020-08-11T20:31:35Z</dc:date>
    </item>
    <item>
      <title>Re: List.Sum throwing error Power Query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1288687#M41002</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="109184" data-lia-user-login="smjzahid" class="lia-mention lia-mention-user"&gt;smjzahid&lt;/a&gt;&amp;nbsp;, is this what you are wanting, what is in the far right "custom" column?&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;If so, your formula should just be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;if [Units] = "Hours" then [Value] else null&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No need for List.Sum. Sorry if I've overcomplicated it. I used List.Sum to total&amp;nbsp;&lt;EM&gt;all rows&lt;/EM&gt; where Units = "Hours" which is why it is 10 for those for rows (1+2+3+4) and null for the kWh rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that still isn't what you need, please give us an example of what you expect. You can screenshot somethig from Excel to mock it up if you want, just explain the logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is what you want, then Power Query is the best place to do this. Power Query excels in this kind of transformation that is done for each record vs trying to access an entire table at a time per record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Aug 2020 21:13:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1288687#M41002</guid>
      <dc:creator>edhans</dc:creator>
      <dc:date>2020-08-11T21:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: List.Sum throwing error Power Query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1327675#M42015</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="109184" data-lia-user-login="smjzahid" class="lia-mention lia-mention-user"&gt;smjzahid&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please check:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Add an Index column.&lt;/P&gt;
&lt;P&gt;2. Convert [Value] to list.&lt;/P&gt;
&lt;P&gt;3. Add a custom column.&lt;/P&gt;
&lt;P&gt;4. Remove Index column.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8sgvLSpW0lEyVIrVQfCMUHjGKDwTMC87PAOuC86OBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Units = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Value", type number}}),
    #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
    Value = #"Added Index"[Value],
    #"Added Custom Column"  = Table.AddColumn(#"Added Index", "Running Total", each if [Units] = "Hours" then List.Sum(List.Range(Value,0,[Index]+1)) else [Value]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom Column",{"Index"})
in
    #"Removed Columns"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, .pbix file attached.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Icey&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post&amp;nbsp;&lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Aug 2020 05:04:52 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/List-Sum-throwing-error-Power-Query/m-p/1327675#M42015</guid>
      <dc:creator>Icey</dc:creator>
      <dc:date>2020-08-27T05:04:52Z</dc:date>
    </item>
  </channel>
</rss>

