Forum Discussion
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:
| Year | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 |
| Contribution | 2500 | 2500 | 2500 | 2500 | 2500 | 2500 | 2500 | 2500 | 2700 | 2500 | 2500 |
| Growth | 50 | 101 | 153.02 | 206.0804 | 260.202008 | 315.406 | 371.7142 | 429.1485 | 491.7314 | 551.566 | 612.5974 |
| Fund Value | 2550 | 5151 | 7804.02 | 10510.1 | 13270.30241 | 16085.71 | 18957.42 | 21886.57 | 25078.3 | 28129.87 | 31242.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
- ronrsnfldSuper User
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?
- Ashish_MathurSuper User
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.
- Raj12Helper III
This is source data is
Age Contribution Investment Growth Fund Value 30 2500 50 2550
Now have to calculate forecasting for further Age yrs i.e. 31,32,33 etc based on calculation thatGrowth = ( This year contribution+Earlier year fund value ) * 0.02
Contribution is constant for all yearsFund Value = This year contribution + Earlier year fund value+ This year Inv growth
- Raj12Helper III
Below is the detailed table to be implemented
(A) Age (B) Contribution (C) Investment Growth (D) Fund Value 30 1174 B2*0.02 =23.48 B2+C2=1197.48 Data Given 31 1174 (B3+D2)*0.02=47.42 B3+C3+D2=2418.90 Forecasting 32 1174 (B4+D3)*0.02=71.85 B4+C4+D3=3664.76 33 1174 96.77535584 4935.54315 34 1174 122.190863 6231.73401 35 1174 148.1146802 7553.84869 36 1174 174.5569738 8902.40566 37 1174 201.5281133 10277.9338