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.
how about now?
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] )
)
)
- giordani20003 years agoHelper I
AlexisOlson got it. SUPER HELPFUL to have a sounding board for issues like this.
WRT learning more and becoming an advanced user of Power Query, Power Pivot and DAX. Any recomendations where to get more free training? I've started watching a few videos from SQLBI.com and myonlinetraininghub. Any better option? Thanks.
- AlexisOlson3 years agoSuper User
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.
- giordani20003 years agoHelper I
Using the same file, I am trying to find out the following:
Attribute =Lead / Category= JB
Attribute = Year of Inv. / Category: select only greater than 2012.
I also want the flexibility to select any attribute and filter by other Attribute.
For this, it is almost like I need Attribute 1 and Attribute 2. The way is designed now, the pivot does not allow me to select Attribute twice. Do I need to create an attribute#2? It will not work bc the pivot table will filter category based on the first attribute.
Ultimately, I want the same number of selections in Attribute 1 and Category 1 in Attribute 2 and Category 2 so I can slice the pivot table any way I want. Thanks.
Test_PivotTable_Inconsistent results_v2.xlsx
- giordani20003 years agoHelper I
Forum, let me know if you need more clarification. I guess I can unpivot column Attribute but I am not sure it is the most efficient solution