Forum Discussion
xIRR calculation discrepancy
- 3 years ago
XIRR is a poorly implemented function. It's finicky and will occasionally fail if you don't give it a good enough guess to start from. For example, in your file, it will return the -69.9% value if you use -0.5 as a guess but fails with -0.01 as you have.
I don't know of a good way around this. I've implemented my own versions of XIRR in SQL before but this isn't feasible in DAX as it cannot handle the recursion required for the algorithm. In my own financial models, I've written measures that give a very rough approximation that I feed into the guess parameter of my IRR measures (currently I use annualized TVPI but I hope to find something better).
In a pinch, you may be able to get away with nested IFERROR functions that try XIRR with different guesses but this is ugly and inefficient:
CALCULATE ( IFERROR ( XIRR ( TestCF, TestCF[Total CF], TestCF[Date], 0.1 ), /*Default guess*/ IFERROR ( XIRR ( TestCF, TestCF[Total CF], TestCF[Date], -0.1 ), IFERROR ( XIRR ( TestCF, TestCF[Total CF], TestCF[Date], -0.5 ), BLANK () ) ) ), FILTER ( ALL ( TestCF ), CONTAINS ( VALUES ( TestSum_2 ), TestSum_2[Portfolio Company], TestCF[Company] ) ) ) - 3 years ago
The file is updated now. The ones it's failing on don't surprise me. IRRs like that are pretty far out of the norm.
Unfortunately, I don't have any further advice other than to tinker with the guesses. You could try using [Loss WE Ratio] as a guess and including as many additional guesses as you feel like. I think the following may work for this specific case but there's no guarantee it will work more broadly. I don't have any silver bullets.
CALCULATE ( IFERROR ( XIRR ( TestCF, TestCF[Total CF], TestCF[Date], 0.1 ), IFERROR ( XIRR ( TestCF, TestCF[Total CF], TestCF[Date], - [Loss WD Ratio] ), IFERROR ( XIRR ( TestCF, TestCF[Total CF], TestCF[Date], -0.5 ), IFERROR ( XIRR ( TestCF, TestCF[Total CF], TestCF[Date], -0.999 ), -1 ) ) ) ), FILTER ( ALL ( TestCF ), CONTAINS ( VALUES ( TestSum_2 ), TestSum_2[Bin], TestCF[Bin] ) ) ) - 3 years ago
Most of my training has been on the job and answering thousands of questions on here and StackOverflow. SQLBI has great articles about DAX. Radacad has good articles too. My new favorite is Data Goblins.
Reading articles and watching videos is nice but to really learn you need to actually solve problems yourself, whether your own or other people's.
Any ideas how to solve this? For an unknown reason the IRR formula is not picking up company Sym but it picks the rest of my 100+ companies in my live file. It may be a problem with the data but I have review it multiple times. Appreciate your feedback.
AlexisOlson I noticed you had contributed to a question related to XIRR in the past. Would you be able to contribute to this problem. See prior posting for a path to the file. Thanks.!
- AlexisOlson3 years agoSuper User
XIRR is a poorly implemented function. It's finicky and will occasionally fail if you don't give it a good enough guess to start from. For example, in your file, it will return the -69.9% value if you use -0.5 as a guess but fails with -0.01 as you have.
I don't know of a good way around this. I've implemented my own versions of XIRR in SQL before but this isn't feasible in DAX as it cannot handle the recursion required for the algorithm. In my own financial models, I've written measures that give a very rough approximation that I feed into the guess parameter of my IRR measures (currently I use annualized TVPI but I hope to find something better).
In a pinch, you may be able to get away with nested IFERROR functions that try XIRR with different guesses but this is ugly and inefficient:
CALCULATE ( IFERROR ( XIRR ( TestCF, TestCF[Total CF], TestCF[Date], 0.1 ), /*Default guess*/ IFERROR ( XIRR ( TestCF, TestCF[Total CF], TestCF[Date], -0.1 ), IFERROR ( XIRR ( TestCF, TestCF[Total CF], TestCF[Date], -0.5 ), BLANK () ) ) ), FILTER ( ALL ( TestCF ), CONTAINS ( VALUES ( TestSum_2 ), TestSum_2[Portfolio Company], TestCF[Company] ) ) )- giordani20003 years agoHelper I
Thanks AlexisOlson this solution, while ugly and ineffient, works. If I may, let me present to you three other instances where the IRR formula does not yield the expected result. Disclosing these issues to you may disclose that I am not an advance power pivot and power query user. Click the link below for an updated file:
https://1drv.ms/x/s!AhK8zgM_1Ab0ds0FGvdGKm1hobA?e=rEFcVi
Would you be able to contribute to this problem?
Additionally, I am super insterested in learning and becoming an advanced user of Power Query and Power Pivot. Any recomendations where to get more free training.
- AlexisOlson3 years agoSuper User
The file looks the same to me.