Forum Discussion

Raj12's avatar
Raj12
Helper III
4 years ago
Solved

Implementing Excel table in Power Bi where a column value depends on another column earlier value

I want to implement an excel table in Power Bi
Ideally I have 1st column data i.e. for year 30th and rest all should populate based on calculation:

 

Year3031323334353637383940
Contribution25002500250025002500250025002500270025002500
Growth 50101153.02206.0804260.202008315.406371.7142429.1485491.7314551.566612.5974
Fund Value 255051517804.0210510.113270.3024116085.7118957.4221886.5725078.328129.8731242.47

 


Growth = ( This year contribution+Earlier year fund value ) * 0.02

Contribution is constant for all years

Fund Value = This contribution + Earlier year fund value+ This year Inv growth

 

I tried creating calculated column but it gives error of circular dependencies and tried creating functions in Power query but still no luck. any help is appreciated

 

Thank you

15 Replies

  • Using Power Query M Code, it is possible to create the table you show from the source data you supply:

    • In this code, the number of years is hard coded
    • The growth rate is calculated from the source data
    • List.Generate is used to generate the required columns
    • I assumed the $2700 contribution in year 38 was a typo

     

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjZQ0lEyMjUAUaYQNpCKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Age = _t, Contribution = _t, #"Investment Growth" = _t, #"Fund Value" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Age", Int64.Type}, 
            {"Contribution", Currency.Type}, {"Investment Growth", Int64.Type}, {"Fund Value", Currency.Type}}),
     
        //calculate new columns
        yrs = 11,
        rate= #"Changed Type"[Investment Growth]{0}/#"Changed Type"[Contribution]{0},
        
        newTblCols = List.Generate(
            ()=>[yr=#"Changed Type"[Age]{0},
                 contr=#"Changed Type"[Contribution]{0},
                 gr=#"Changed Type"[Investment Growth]{0},
                 fv=#"Changed Type"[Fund Value]{0}, 
                 idx=0],
            each [idx] < yrs,
            each [yr=[yr]+1,
                  contr=[contr],
                  gr = ([fv] + [contr]) * rate,
                  fv = [fv] + [contr] + ([fv] + [contr]) * rate,
                  idx = [idx]+1],
            each {[yr],[contr],[gr],[fv]}
        ),
    
    //create table from columns and prepend with a column for the Row labels
        #"New Table" = Table.FromColumns({{"Year","Contribution","Growth","Fund Value"}} & newTblCols),
    
    //Promote first row to the column Headers
        #"Promoted Headers" = Table.PromoteHeaders(#"New Table", [PromoteAllScalars=true]),
    
    //Set the data types for new table
        #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers",{{"Year", type text}} & 
            List.Transform(List.RemoveFirstN(Table.ColumnNames(#"Promoted Headers"),1), each {_, Currency.Type}))
    in
        #"Changed Type1"

     

     

    But, as you show in your example, this is three rows of results for a single entry row.

    How would you want to display the results when you have multiple entry rows?

     

  • Hi,

    Share the source data (not the expected result which you have pasted in the original message) in a format that can be pasted in an MS Excel file.

    • Raj12's avatar
      Raj12
      Helper III

      This is source data is 

      AgeContributionInvestment Growth Fund Value 
      302500502550


      Now have to calculate forecasting for further Age yrs i.e. 31,32,33 etc based on calculation that

      Growth = ( This year contribution+Earlier year fund value ) * 0.02
      Contribution is constant for all years

      Fund Value = This year contribution + Earlier year fund value+ This year Inv growth

      • Raj12's avatar
        Raj12
        Helper III

        Below is the detailed table to be implemented

        (A) Age(B) Contribution(C) Investment Growth (D) Fund Value  
        301174B2*0.02 =23.48 B2+C2=1197.48Data Given
        311174(B3+D2)*0.02=47.42B3+C3+D2=2418.90Forecasting
        321174(B4+D3)*0.02=71.85B4+C4+D3=3664.76
        33117496.775355844935.54315
        341174122.1908636231.73401
        351174148.11468027553.84869
        361174174.55697388902.40566
        371174201.528113310277.9338