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
Raj12
Helper II
Helper II

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

1 ACCEPTED SOLUTION

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

15 REPLIES 15
ronrsnfld
Super User
Super User

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

ronrsnfld_0-1652099395908.png

  • 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"

 

 

ronrsnfld_0-1652099680196.png

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_Mathur
Super User
Super 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.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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

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

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Its a great solution, just one thing:

Measure  for **Contri = SUM(Data[Contribution])** which will add in all contribution in the data but my data has only 1st row contribution in there i.e. for today

AgeContribution
301174

like below (from your file table: Data )only 1st row data is present and not for all upcomming years and can't create all years contribution in that table as there are more than 1million individual records for which I want this forecasting

ContributionDate
1174Tuesday 1 January 2030

Hi,

I know of a way to explode that 1 row into 8 rows but that would mean giving rise to 8 million rows from your original dataset of 1 million rows.  I dont think my solution will work efficiently there.  Sorry but i cannot help here.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you for your response.

 

Can't we take **Contri** measure as given value for each unique record and use it for calculating forecasting for other subsequent years as for other years **Contri* will remain same.

I do not know of a way to do that.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Okay and how can we get sum of a measure in there like if I take Fund value in a card visual then it shows only the last value not the sum of all the rows for fund value  as shown below

Raj12_0-1652095807539.png

 

Write this measure

Measure = if(HASONEVALUE('Calendar'[Year]),[Fund value],SUMX(VALUES('Calendar'[Year]),[Fund value]))

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you so much for the help .

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Jus one small thing.
I am trying to add in some initial fund value value in first year fund value only and subsequent calculation is as it is. Is it spossible?

Raj12_0-1652195346975.png

 

Tried to update existing meausre of Fund Value as:
Fund Value__ =
var val = [Inv till date__]+[Inv grwoth till date__]
return
if([Years elapsed]=1,val+SUM('Data'[Inital Fund]),val)

but it just adds in initial fund column value in 1st row but subsequent rows calulcation is not taking that added in value

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