web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to calculate Inter...
Power Apps
Suggested Answer

How to calculate Internal Rate of Return (IRR)

(0) ShareShare
ReportReport
Posted on by 44

Hi, everyone,
 
is there anyone who knows how to calculate IRR within Power Apps, below you can find the implementation of code based on vague description of ChatGPT but I am not sure whether it is correct or not. Did not find any official documentation for IRR excel function from which I could reverse engineer it.
 
Visual Basic has its own library with financial functions where IRR is available but unfortunately I was not able to reproduce it.

Description for IRR function:
Returns the internal rate of return for a series of cash flows represented by the numbers in values. These cash flows do not have to be even, as they would be for an annuity. However, the cash flows must occur at regular intervals, such as monthly or annually. The internal rate of return is the interest rate received for an investment consisting of payments (negative values) and income (positive values) that occur at regular periods.
 
Any help or advice would be greatly appreciated. I know the code might be incomprehensible so feel free to ask any question, I will try to respond to them ASAP.
 
/*
- col_MERCURY_BC_ROP is local collection where all cashflows are stored in record type column hence the ungroup function, basically one row has a column PROFIT_ROP is a record with additional 50 rows (yearCount),
- the arrCashFlows within "With" function is a array of profits which are calculated based on internal formula
*/
Clear(col_Results);
With(
    {   
        locRate: 0.1, // starting guess for IRR (10%)
        locAccuracy: 0.01,
        //cash flows in array
        arrCashFlows: 
                /*internal formula*/
                ForAll(
                    Sequence(yearCount) /*yearCount is static value = 50*/ As aRecord,
                        {
                            profit: 
                                /*calculate individual cashflows*/
                                Sum(
                                    Filter(Ungroup(ShowColumns(col_MERCURY_BC_ROP, PROFIT_ROP, POCET_HP_IK1), PROFIT_ROP), Year = Text(LookUp(yearMatrix, Value(Y) = Value(aRecord.Value - 1)).Year)), POCET_HP_IK1 * Value
                                ),
                            y: aRecord.Value - 1
                        }    
                )
    },
    ForAll(
        Sequence(100, 0, 0.01) As rRecord,
        Collect(col_Results,
            {
                locRate: rRecord.Value - 1,
                /*calculate npv*/
                locNpv: Sum(
                        ForAll(
                            Sequence(yearCount) As nRecord, 
                                Round(
                                    /*calculate individual cashflows*/
                                    Sum(
                                        Filter(
                                            Ungroup(
                                                ShowColumns(col_MERCURY_BC_ROP, PROFIT_ROP, POCET_HP_IK1), PROFIT_ROP), Value(Year) <= Value(LookUp(yearMatrix, Value(Y) = Value(nRecord.Value - 1)).Year)
                                                ), POCET_HP_IK1 * Value)
                                    * 
                                    (
                                        1 / Power((1 + Value(Substitute(txt_wacc_input.Value, ",", "."))), nRecord.Value - 1)
                                    ),
                                2)
                            ), Value
                    )
            }
        )
    )
);
/*find closest positive value to 0*/
Set(varIRR, Text(First(SortByColumns(Filter(LastN(col_Results, 999), Abs(locRate) < 0.01), "locRate", SortOrder.Ascending)).locRate, "0.00%"))
 
Thank you all.
 
Cheers
Krystof
Categories:
I have the same question (0)
  • Nandit Profile Picture
    1,568 Moderator on at
     
    I would like to try this. Can you share in psuedocode how the IRR function in excel works? Like in simple language just share how this function takes the array of values and optional starting guess then calculates it?
     
    That would be super helpful
     
    Kind regards, 
    Nandit
  • Nandit Profile Picture
    1,568 Moderator on at
    Hi,

    Following up to check if you were able to solve this issue? Please post the answer if you solved it.

    Kind regards,
    Nandit
  • Suggested answer
    krystofpe Profile Picture
    44 on at
    Hello @Nandit,
     
    Thank you for your feedback. I was not able to reproduce the IRR function but I was able to use OfficeScripts in Power Automate to achieve IRR. I am sending array of values which are then processed via "Run script" action.
     
    Best regards
    Krystof

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard