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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

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
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors