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
Deem
Frequent Visitor

Life Cycle Calculation

Hi everyone,

 

I would like to get the following output in PowerBI. I've read a different post with a solved solution but unfortunately  I can't reproduce the solution without an error. I've asked a question about it in that forum post but unfortunately nobody answers it. Therefore I've opened this new post and I hope someone can help me with a working solution. Old post: Solved: Asset Life Cycle Calculation - Microsoft Power BI Community

 

I need PowerBI to create the following table. Every AssetNo has to be replaced after it's expected Life for a fixed amount of costs. The next step would be to integrate a index so the replacements cost wil be indexed every year.

Deem_0-1664738108262.png

 

The calculated tabled is based on the following dataset. For example every 5 year AssetNo A has to be replaced for a value of € 1.000,--.

AssetNo  endyear  life  Assetcost
A20185€ 1.000
B20193€ 2.000
C20205€ 1.500
D20176€ 1.000

 

I've build the following function that will provide a list of replacement years for each last replacement year. This gives an error.

 

 

 

 

let
output = List.Generate(
    ()=>[firstValue],
    each _<= [endyear], each _+[life],
    each _
)
in
output

 

 

 

 

 

This function creates a list but comes withe an error when I expand the list to new rows.

Deem_3-1664739522637.png

 

When I expand to new rows I get the following error. "Expression.Error: We cannot apply field access to the type Number."

Deem_4-1664739541568.png

 

When I place a fixed value for endyear (2050) and life (5) then it works fine. I can live wit a fixed value but the value live comes from the dataset.

 

 

 

 

let
output = List.Generate(
    ()=>[firstValue],
    each _<= 2050, each _+5,
    each _
)
in
output

 

 

 

 

The output is with tunnecessary columns deleted is:

Deem_8-1664739806348.png

 

Does somebody know a solotion for this problem or a different method in PowerBI. Thanks in advance.


Damon

 

https://1drv.ms/u/s!AvqOdziejqaXluYnp2YAh2Bpk5SYqA?e=oALPaS 

 

 

1 ACCEPTED SOLUTION

Hi , @Deem 

I download your .pbix file , For your problem, Here are my answers:

(1)At present, the value you modified is correct, and you can return the correct table, where 2050 means that the year of the generation stops in 2050, and the deadline for the generation is not specified in your table, so you need to replace the value with 2050.

vyueyunzhmsft_0-1664785316170.png

(2)For the [life] field , you can edit the M language in  "Aangepaste kolom toegevoegd" step:

= Table.AddColumn(#"Type gewijzigd", "Aangepast", (x)=> List.Generate(()=>x[endyear]+x[life],(y)=> y<=2050 , (y)=>y+x[life] )   )

vyueyunzhmsft_1-1664785586224.png

 

Best Regards,

Aniya Zhang

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

8 REPLIES 8
v-yueyunzh-msft
Community Support
Community Support

Hi, @Deem 

I test it with your data, Here are the steps you can refer to :

(1)This is my test data:

vyueyunzhmsft_0-1664778520758.png

(2)We can Add a custom colimn in Power BI Query Editor:

(x)=> List.Generate(()=>x[Last Replaced],(y)=>y<=Number.From(x[End of Year]) ,(y)=>y+Number.From(x[Expected Life])   )

vyueyunzhmsft_1-1664778586906.png

(3)Then we can click "Expand to Mew Rows".

vyueyunzhmsft_2-1664778601923.png

(3)Then we aplly the data to the Power BI Desktop and we can put the field in the visual and we will meet your need:

vyueyunzhmsft_3-1664778648315.png

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

Best Regards,

Aniya Zhang

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

 

 

 

 

 

 

 

Hi @v-yueyunzh-msft,

 

Thank for your quick response. It looks great. Unfortunately I get a new column with function. And I can't open your Pbix because is searching for a Excelfile.

I will attach my original dataset in the opneing post.

Deem_0-1664780042118.png

 

 

 

Hi, @Deem 

You can try to delete the "each" in the enter box :

 

vyueyunzhmsft_0-1664781574663.png

Then you can get the list .

 

Best Regards,

Aniya Zhang

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

 

 

Hi @v-yueyunzh-msft ,

 

Sorry but removing each doesn't work. At the bottom of my original post I've added a Onedrive downloadlink of my pbix . Can you pleas have a look at it. Thanks.

Greg_Deckler
Super User
Super User

@Deem Here is a DAX solution. Basically Blowout! PBIX is attached below sig.

Blowout! = 
    VAR __Table =
        GENERATE(
        'Table',
            VAR __MinYear = [endyear]
            VAR __increment = [life]
        RETURN GENERATESERIES(__MinYear,__MinYear + __increment * 3,__increment)
    )
RETURN
    __Table

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

HI @Greg_Deckler ,

 

I wil try this solution later this day on my big dataset. I've tried it and it works on the test dataset. I will let you know if it works fine. Thanks!

Deem
Frequent Visitor

Hi @Greg_Deckler , your solutions works also fine. The only thing is that it generates much more new rows because of the incrementfactor then the solution of @v-yueyunzh-msft. So I have chosen the solution of @v-yueyunzh-msft for my case.

 

Many thanks for your quick replies!!💪💪

Hi , @Deem 

I download your .pbix file , For your problem, Here are my answers:

(1)At present, the value you modified is correct, and you can return the correct table, where 2050 means that the year of the generation stops in 2050, and the deadline for the generation is not specified in your table, so you need to replace the value with 2050.

vyueyunzhmsft_0-1664785316170.png

(2)For the [life] field , you can edit the M language in  "Aangepaste kolom toegevoegd" step:

= Table.AddColumn(#"Type gewijzigd", "Aangepast", (x)=> List.Generate(()=>x[endyear]+x[life],(y)=> y<=2050 , (y)=>y+x[life] )   )

vyueyunzhmsft_1-1664785586224.png

 

Best Regards,

Aniya Zhang

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

 

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