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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
AlvWib
New Member

Expression Error, we cannot convert the value 0 to typle List

Hi all,

I am quite new with PowerQuery and need your help to identify the mistake of my PowerQuery Codes. The case is about doing Running Total.


I have a dataset / table containing column "Material", "Week" and "SUMIFS". This Column "SUMIFS" is already the result of another step, which you will see in my codes. Column "RunningTotal" is the intended result. The idea is to do cumulative iteration per Material.

 

MaterialWeekSUMIFSRunningTotal
A1100100
A210110
A330140
B17070
B22090
B3595
C18080
C2080
C3181


Here is my PowerQuery Code

let
    Source = Excel.Workbook(File.Contents("C:\Users\wibowoal\Desktop\Test.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Material", type text}, {"Field", type text}, {"Week", Int64.Type}, {"Qty", Int64.Type}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Changed Type",{"Material", "Week"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Other Columns"),
    #"Added Custom" = Table.AddColumn(#"Removed Duplicates", "SUMIFS", each List.Sum(
    Table.SelectRows(
    DataSource,
    (InnerTable) => InnerTable[Material] = [Material] and
    InnerTable[Week] = [Week]
)[Final Quantity]
)),
    #"Added Index" = Table.AddIndexColumn(#"Added Custom", "Index", 1, 1, Int64.Type),
    #"GroupMaterial" = Table.Group(#"Added Index", {"Material"}, {
        {"RunningTotal", each List.Buffer(List.Generate(
        () => [RunningTotal=0, PrevWeek=0, Index=0],
        each [Index] <= List.Max([Index]),
        each [


            RunningTotal= [RunningTotal] + #"Added Index"[SUMIFS],


            PrevWeek=[Week],
            Index=[Index]+1
        ],
        each [RunningTotal]
        )), type list}
    }),
    #"Expanded" = Table.ExpandListColumn(#"GroupMaterial", "RunningTotal")
in
    #"Expanded"


However, I got the error message as follows: "Expression.Error: We cannot convert the value 0 to type List. Details: Value = 0, Type=[Type]. PowerQuery starts to show this error during #"GroupMaterial" step.

 

Really appreciate the help! 🙂

1 REPLY 1
AlexisOlson
Super User
Super User

This part looks suspicious to me:

each [Index] <= List.Max([Index]),

List.Max expects a list, not a 0.

I'd recommend checking out this article for ideas on how to fix your running total more generally:
https://gorilla.bi/power-query/running-total-by-category/

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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