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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Alekis
New Member

accumulated of zero

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Fonte = Excel.Workbook(File.Contents("C:\Users\alex\Desktop\\stock_acumulated.xlsx"), null, true),
    stock_Table = Fonte{[Item="stock",Kind="Table"]}[Data],
    #"start" = Table.TransformColumnTypes(stock_Table,{{"code", Int64.Type}, {"date", type date}, {"trans_id", Int64.Type}, {"Index", Int64.Type}, {"amount", Int64.Type}, {"day amount", Int64.Type}}),
    ListOfIndex = List.Buffer(#"start"[Index]),
    ListOfamount = List.Buffer(#"start"[amount]),
    //Function Start
    fxGetAccum=(ListOfIndex, ListOfamount)=>
        let
            FunctionResult = List.Generate(()=>[x=ListOfamount{0},i=0], each [i]<List.Count(ListOfIndex), each [i=[i]+1, x=(if ListOfIndex{i}=0 then 0 else [x]) + ListOfamount{i}], each [x])
        in
            FunctionResult,
    //Function End
    Result = Table.FromColumns(Table.ToColumns(#"start")&{fxGetAccum(ListOfIndex, ListOfamount)},Table.ColumnNames(#"start")&{"Accumulated"})
in
    Result

 

View solution in original post

2 REPLIES 2
Alekis
New Member

great, where  can'I learn  this about ?

Vijay_A_Verma
Super User
Super User

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Fonte = Excel.Workbook(File.Contents("C:\Users\alex\Desktop\\stock_acumulated.xlsx"), null, true),
    stock_Table = Fonte{[Item="stock",Kind="Table"]}[Data],
    #"start" = Table.TransformColumnTypes(stock_Table,{{"code", Int64.Type}, {"date", type date}, {"trans_id", Int64.Type}, {"Index", Int64.Type}, {"amount", Int64.Type}, {"day amount", Int64.Type}}),
    ListOfIndex = List.Buffer(#"start"[Index]),
    ListOfamount = List.Buffer(#"start"[amount]),
    //Function Start
    fxGetAccum=(ListOfIndex, ListOfamount)=>
        let
            FunctionResult = List.Generate(()=>[x=ListOfamount{0},i=0], each [i]<List.Count(ListOfIndex), each [i=[i]+1, x=(if ListOfIndex{i}=0 then 0 else [x]) + ListOfamount{i}], each [x])
        in
            FunctionResult,
    //Function End
    Result = Table.FromColumns(Table.ToColumns(#"start")&{fxGetAccum(ListOfIndex, ListOfamount)},Table.ColumnNames(#"start")&{"Accumulated"})
in
    Result

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors