Skip to main content

Notifications

Community site session details

Community site session details

Session Id : WDw6X67AG6yf0EbGLt4EuD
Power Apps - Building Power Apps
Suggested answer

How to calculate Internal Rate of Return (IRR)

Like (0) ShareShare
ReportReport
Posted on 25 Oct 2024 13:16:54 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
  • Suggested answer
    krystofpe Profile Picture
    44 on 04 Nov 2024 at 07:30:53
    How to calculate Internal Rate of Return (IRR)
    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
  • Nandit Profile Picture
    1,563 Super User 2025 Season 1 on 31 Oct 2024 at 09:13:00
    How to calculate Internal Rate of Return (IRR)
    Hi,

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

    Kind regards,
    Nandit
  • Nandit Profile Picture
    1,563 Super User 2025 Season 1 on 28 Oct 2024 at 10:59:51
    How to calculate Internal Rate of Return (IRR)
     
    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

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Apps - Building Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 89 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 60

#3
stampcoin Profile Picture

stampcoin 48

Overall leaderboard
Loading started