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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
SonLeThai
Frequent Visitor

Circular Dependency in power bi!!! Need Help.......

Hi Comunity,
I wanna to make a table like this table in excel:

SonLeThai_0-1705553205300.png

In case:
Index 0: Ending Value = 12
Index 1: Begin Value = Previous Ending Value = 12, Import Value = 13, Export Value = (Begin + Import)/2 = 12.5, Ending Value = Begin + Import - Export = 12.5
Index 2: Begin Value = Previous Ending Value = 12.5, Import Value = 11, Export Value = (Begin + Import)/2 = 11.75, Ending Value = Begin + Import - Export = 11.75
....
I try do it in PBI but get Circular Dependency on Col Ending.
Please help me make that table!!
Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @SonLeThai ,

Here is my sample data:

vjunyantmsft_0-1705994557182.png

Then you can try this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUQIiQyOlWJ1oJUMQ0xgkBOIZgXiGMB5I2NAExgMxDE3BvFgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, Import = _t, Value = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Index", Int64.Type}, {"Import", Int64.Type}, {"Value", Int64.Type}}),
    InitialEnding = 12,

    AccumulateColumns = List.Accumulate(

        List.Zip({ChangedType[Index], ChangedType[Import]}), 

        {[Index=0, Begin=null, Export=null, Ending=InitialEnding]},

        (state, current) => 

        let

            CurrentIndex = current{0},

            CurrentImport = current{1},

            PreviousEnding = if CurrentIndex = 0 then null else state{CurrentIndex}[Ending],

            CurrentExport = if CurrentIndex = 0 then null else (PreviousEnding + CurrentImport) / 2,

            CurrentEnding = if CurrentIndex = 0 then InitialEnding else PreviousEnding + CurrentImport - CurrentExport,

            CurrentRecord = [Index=CurrentIndex, Begin=PreviousEnding, Export=CurrentExport, Ending= CurrentEnding]

        in

            state & {CurrentRecord}

    ),

    AccumulatedTable = Table.FromRecords(AccumulateColumns),

    JoinedTable = Table.NestedJoin(ChangedType,{"Index"},AccumulatedTable,{"Index"},"NewColumns",JoinKind.LeftOuter),

    ExpandedTable = Table.ExpandTableColumn(JoinedTable, "NewColumns", {"Begin", "Export", "Ending"}),

    FinalTable = ExpandedTable,
    #"Removed Top Rows" = Table.Skip(FinalTable,1)

in

    #"Removed Top Rows"

Put all of the M code into Advanced Editor, and the final output is below:

vjunyantmsft_1-1705994764791.png

 

Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @SonLeThai ,

Here is my sample data:

vjunyantmsft_0-1705994557182.png

Then you can try this:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUQIiQyOlWJ1oJUMQ0xgkBOIZgXiGMB5I2NAExgMxDE3BvFgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Index = _t, Import = _t, Value = _t]),
    ChangedType = Table.TransformColumnTypes(Source,{{"Index", Int64.Type}, {"Import", Int64.Type}, {"Value", Int64.Type}}),
    InitialEnding = 12,

    AccumulateColumns = List.Accumulate(

        List.Zip({ChangedType[Index], ChangedType[Import]}), 

        {[Index=0, Begin=null, Export=null, Ending=InitialEnding]},

        (state, current) => 

        let

            CurrentIndex = current{0},

            CurrentImport = current{1},

            PreviousEnding = if CurrentIndex = 0 then null else state{CurrentIndex}[Ending],

            CurrentExport = if CurrentIndex = 0 then null else (PreviousEnding + CurrentImport) / 2,

            CurrentEnding = if CurrentIndex = 0 then InitialEnding else PreviousEnding + CurrentImport - CurrentExport,

            CurrentRecord = [Index=CurrentIndex, Begin=PreviousEnding, Export=CurrentExport, Ending= CurrentEnding]

        in

            state & {CurrentRecord}

    ),

    AccumulatedTable = Table.FromRecords(AccumulateColumns),

    JoinedTable = Table.NestedJoin(ChangedType,{"Index"},AccumulatedTable,{"Index"},"NewColumns",JoinKind.LeftOuter),

    ExpandedTable = Table.ExpandTableColumn(JoinedTable, "NewColumns", {"Begin", "Export", "Ending"}),

    FinalTable = ExpandedTable,
    #"Removed Top Rows" = Table.Skip(FinalTable,1)

in

    #"Removed Top Rows"

Put all of the M code into Advanced Editor, and the final output is below:

vjunyantmsft_1-1705994764791.png

 

Best Regards,
Dino Tao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

The only way you can do this is in Power Query using List.Accumulate.

I try List.Accumulate but it not working right.
I try to make it by While Loop in Power Editor but i think it will be slow with large data.

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.