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

Rolling XIRR Calculation

Hello there,

 

I am trying to build a rolling IRR calculation for an investment return report. No mater what I try, I cannot seem to get PBI to return a value for my formula. Can anyone help.

 

ROLLING IRR = CALCULATE(
XIRR('INVESTMENT RETURNS','INVESTMENT RETURNS'[FREE CASHFLOW FOR PERIOD],'INVESTMENT RETURNS'[DATE])
,FILTER('INVESTMENT RETURNS',EARLIER('INVESTMENT RETURNS'[Index])>='INVESTMENT RETURNS'[Index]))

There are six rows in my test table as follows:

 

IndexFREE CASHFLOW FOR PERIODDATE
42- 7,531,293.0030/06/2013
43     859,425.0030/06/2014
44     901,305.0030/06/2015
45     951,189.0030/06/2016
46  7,742,641.0030/06/2017
47  1,498,289.0030/06/2018

 

Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

Hi @v-ljerr-msft,

 

Thank you very much for your help! 

 

The formula works great, although I have made a few tweaks to include:

 - a terminal value (from the [equity repayment/(investment) on sale] column) to be calculated at the end of each period and calculated in the XIRR calc (i.e. if I sold the investment now, what would my XIRR be), and

 - a check to ensure that there is at least one positive cashflow (another requirement of the XIRR formula along with the first periof being negative).

 

see my code as follows fyi.... 

ROLLING XIRR = 
VAR countpos =
    CALCULATE(
        COUNT('INVESTMENT RETURNS'[totalcashflow]),
            FILTER(ALL('INVESTMENT RETURNS'), 'INVESTMENT RETURNS'[totalcashflow]>0 && EARLIER ('INVESTMENT RETURNS'[Index] ) >= 'INVESTMENT RETURNS'[Index] && 'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] )
              )
           )

VAR minIndex =
    CALCULATE (
        MIN ( 'INVESTMENT RETURNS'[Index] ),
        FILTER (
            ALL ( 'INVESTMENT RETURNS' ),
            'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] )
        )
    )
VAR firstValue =
    CALCULATE (
        MIN ( 'INVESTMENT RETURNS'[FREE CASHFLOW FOR PERIOD (excl. sale)] ),
        FILTER (
            ALL ( 'INVESTMENT RETURNS' ),
            'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] )
                && 'INVESTMENT RETURNS'[Index] = minIndex
        )
    )
RETURN
    IF (
        'INVESTMENT RETURNS'[Index] > minIndex
            && firstValue < 0
            && countpos >= 1 ,
            XIRR (
                UNION( 
                    SUMMARIZE( 
                        FILTER(ALL ( 'INVESTMENT RETURNS' ), EARLIER ('INVESTMENT RETURNS'[Index] ) >= 'INVESTMENT RETURNS'[Index] && 'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] ))
                        ,'INVESTMENT RETURNS'[Index],
                        "DATE1",MAX('INVESTMENT RETURNS'[DATE]),
                        "CASHFLOW",MAX('INVESTMENT RETURNS'[FREE CASHFLOW FOR PERIOD (excl. sale)])
                            ),
                    SUMMARIZE(
                        FILTER(ALL ( 'INVESTMENT RETURNS' ), EARLIER ('INVESTMENT RETURNS'[Index] ) = 'INVESTMENT RETURNS'[Index] ),
                        'INVESTMENT RETURNS'[Index],
                        "DATE1",MAX('INVESTMENT RETURNS'[DATE]),
                        "CASHFLOW",MAX('INVESTMENT RETURNS'[EQUITY REPAYMENT/(INVESTMENT) ON SALE])
                            )
                ),
                [CASHFLOW],
                [DATE1]
            )
    )

Thanks again for all your help. Much appreciated.

 

MJ

 

 

View solution in original post

16 REPLIES 16
v-ljerr-msft
Employee
Employee

Hi @mjfigg,

 

Based on my test, you should be able to use the formula below to build a rolling IRR in your scenario. Smiley Happy

ROLLING IRR = 
VAR minIndex =
    CALCULATE ( MIN ( 'INVESTMENT RETURNS'[Index] ), ALL ( 'INVESTMENT RETURNS' ) )
RETURN
    IF (
        'INVESTMENT RETURNS'[Index] > minIndex,
        CALCULATE (
            XIRR (
                'INVESTMENT RETURNS',
                'INVESTMENT RETURNS'[FREE CASHFLOW FOR PERIOD],
                'INVESTMENT RETURNS'[DATE]
            ),
            FILTER (
                'INVESTMENT RETURNS',
                EARLIER ( 'INVESTMENT RETURNS'[Index] ) >= 'INVESTMENT RETURNS'[Index]
            )
        )
    )

r1.PNG

 

Regards

Hey there!

 

Thanks, the code worked great. However, I just realised that I will actually need another filter on the table for company name, as there will be multiple companies that an XIRR will need to be calculated for. See updated data below. Could you still help me?

 

NameIndexFREE CASHFLOW FOR PERIODDATE
Company A42-7,531,293.0030/06/2013
Company A43     859,425.0030/06/2014
Company A44     901,305.0030/06/2015
Company A45     951,189.0030/06/2016
Company A46  7,742,641.0030/06/2017
Company A47  1,498,289.0030/06/2018
Company B48-840191830/06/2014
Company B4994974730/06/2015
Company B5094238830/06/2016
Company B5194375630/06/2017
Company B52104908930/06/2018

Hi @mjfigg,

 

Sure! The formula below should work in this new scenario. Smiley Happy

ROLLING IRR = 
VAR minIndex =
    CALCULATE (
        MIN ( 'INVESTMENT RETURNS'[Index] ),
        FILTER (
            ALL ( 'INVESTMENT RETURNS' ),
            'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] )
        )
    )
RETURN
    IF (
        'INVESTMENT RETURNS'[Index] > minIndex,
        CALCULATE (
            XIRR (
                'INVESTMENT RETURNS',
                'INVESTMENT RETURNS'[FREE CASHFLOW FOR PERIOD],
                'INVESTMENT RETURNS'[DATE]
            ),
            FILTER (
                'INVESTMENT RETURNS',
                EARLIER ( 'INVESTMENT RETURNS'[Index] ) >= 'INVESTMENT RETURNS'[Index]
                    && 'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] )
            )
        )
    )

r3.PNG

 

Regards

Hi @v-ljerr-msft,

 

Apologies to keep on bothering you... however I cannot seem to get your formula to work on my actual data set. I have copied this below so we can see if you have any issues either. Thanks so much.

 

MJ

 

NameFINANCIAL YEARDISTRIBUTIONSEQUITYtempEQUITY BALANCEROINET ASSET VALUE ON SALEIndexACTUAL EQUITY MOVEMENTSEQUITY REPAYMENT/(INVESTMENT) ON SALEFREE CASHFLOW FOR PERIODDATE
Company A2012      220,000.0096295729,629,5722.30%8,544,134.210-9,629,572-1,085,438-9,409,57230/06/2012
Company A2013   1,309,598.00 9,629,57213.60%8,279,143.5410-1,350,4281,309,59830/06/2013
Company A2014   1,748,073.00 9,629,57218.20%8,250,943.4920-1,378,6291,748,07330/06/2014
Company A2015   2,865,402.00############11,450,40025.00%25,753,143.933-1,820,82814,302,7441,044,57430/06/2015
Company A2016   3,627,947.00 9,629,57237.70%26,247,601.4341,820,82816,618,0295,448,77530/06/2016
Company A2017   3,326,656.00 9,629,57234.50%65,531,598.875055,902,0273,326,65630/06/2017
Company A2018   4,336,035.00 9,629,57245.00%65,463,524.706055,833,9534,336,03530/06/2018
Company A2019   4,618,150.00 9,629,57248.00%65,473,159.837055,843,5884,618,15030/06/2019
Company A2020   5,275,995.00 9,629,57254.80%65,471,361.848055,841,7905,275,99530/06/2020
Company A2021   5,323,785.00 9,629,57255.30%65,471,209.619055,841,6385,323,78530/06/2021
Company A2022   4,949,933.00 9,629,57251.40%65,471,339.5810055,841,7684,949,93330/06/2022
Company B2011                        -  19/02/95662,800,0000.00%2,668,345.5011-2,800,000-131,655-2,800,00030/06/2011
Company B2012      266,730.00 2,800,0009.50%2,646,045.08120-153,955266,73030/06/2012
Company B2013      267,272.00 2,800,0009.50%2,846,349.3513046,349267,27230/06/2013
Company B2014      301,676.00 2,800,00010.80%2,868,516.1814068,516301,67630/06/2014
Company B2015      320,209.00 2,800,00011.40%3,711,889.98150911,890320,20930/06/2015
Company B2016      422,263.00 2,800,00015.10%3,724,043.17160924,043422,26330/06/2016
Company B2017      441,096.00 2,800,00015.80%3,691,333.20170891,333441,09630/06/2017
Company B2018      261,140.0028000002,800,0009.30%5,966,728.351803,166,728261,14030/06/2018
Company B2019      189,619.0028000002,800,0006.80%6,156,209.631903,356,210189,61930/06/2019
Company B2020         20,898.0028000002,800,0000.70%6,306,108.412003,506,10820,89830/06/2020
Company B2022      500,000.0028000002,800,00017.90%6,242,283.162103,442,283500,00030/06/2022
Company C2011      659,079.00100100659079.00%9,331,458.8122-1009,331,359658,97930/06/2011
Company C2012      540,616.00 100540616.00%9,277,099.062309,276,999540,61630/06/2012
Company C2013      742,004.00159820159,820464.30%9,258,662.8124-159,7209,098,843582,28430/06/2013
Company C2014      845,771.00 100845771.00%9,265,568.3425159,7209,265,4681,005,49130/06/2014
Company C2015   1,073,678.00 1001073678.00%11,398,818.4926011,398,7181,073,67830/06/2015
Company C2016   1,121,581.00 1001121581.00%11,434,088.1827011,433,9881,121,58130/06/2016
Company C2017   1,316,995.00 1001316995.00%11,394,817.5928011,394,7181,316,99530/06/2017
Company C2018   1,557,526.001001001557526.50%11,396,678.1829011,396,5781,557,52630/06/2018
Company D2013         68,707.0076000007,600,0000.90%7,292,257.5842-7,600,000-307,742-7,531,29330/06/2013
Company D2014      859,425.00 7,600,00011.30%7,345,734.20430-254,266859,42530/06/2014
Company D2015      901,305.00 7,600,00011.90%7,375,734.52440-224,265901,30530/06/2015
Company D2016      951,189.00 7,600,00012.50%9,588,364.564501,988,365951,18930/06/2016
Company D2017   4,428,202.0042855614,285,561103.30%3,997,812.72463,314,439-287,7487,742,64130/06/2017
Company D2018   1,498,289.00 4,285,56135.00%0470-4,285,5611,498,28930/06/2018
Company E2014      273,082.0086750008,675,0003.10%8,398,839.4548-8,675,000-276,161-8,401,91830/06/2014
Company E2015      949,747.00 8,675,00010.90%8,642,316.32490-32,684949,74730/06/2015
Company E2016      942,388.00 8,675,00010.90%8,846,768.55500171,769942,38830/06/2016
Company E2017      943,756.00 8,675,00010.90%9,870,640.335101,195,640943,75630/06/2017
Company E2018   1,049,089.0086750008,675,00012.10%12,085,226.385203,410,2261,049,08930/06/2018
Company E2019   1,119,677.0086750008,675,00012.90%11,969,884.175303,294,8841,119,67730/06/2019
Company E2020      625,193.0086750008,675,0007.20%11,849,969.145403,174,969625,19330/06/2020
Company E2021      871,440.0086750008,675,00010.00%11,702,695.725503,027,696871,44030/06/2021
Company E2022   1,069,488.0086750008,675,00012.30%11,515,814.915602,840,8151,069,48830/06/2022
Company F2015      218,605.0037365003,736,5005.90%4,251,481.9857-3,736,500514,982-3,517,89530/06/2015
Company F2016      160,000.00 3,736,5004.30%4,677,717.90580941,218160,00030/06/2016
Company F2017      190,000.00 3,736,5005.10%4,840,240.825901,103,741190,00030/06/2017
Company F2018                        -  37365003,736,5000.00%5,545,139.516001,808,640030/06/2018
Company F2019      253,741.0037365003,736,5006.80%5,544,110.506101,807,610253,74130/06/2019
Company F2020      578,817.0037365003,736,50015.50%5,543,677.066201,807,177578,81730/06/2020
Company F2021      606,588.0037365003,736,50016.20%5,543,616.036301,807,116606,58830/06/2021
Company F2022      640,160.0037365003,736,50017.10%5,543,546.626401,807,047640,16030/06/2022

Hi @mjfigg,

The value is calculated as the rate that satisfies the following function:

XIRR Formula

The series of cash flow values must contain at least one positive number and one negative number.




After I a few test, I find the issue is with your data of Company C(there are only positive numbers, but no nagative number).

 

So you may need to correct your data, or use the the formula below to make it work. Smiley Happy

ROLLING IRR =
VAR minIndex =
    CALCULATE (
        MIN ( 'INVESTMENT RETURNS'[Index] ),
        FILTER (
            ALL ( 'INVESTMENT RETURNS' ),
            'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] )
        )
    )
VAR firstValue =
    CALCULATE (
        MIN ( 'INVESTMENT RETURNS'[FREE CASHFLOW FOR PERIOD] ),
        FILTER (
            ALL ( 'INVESTMENT RETURNS' ),
            'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] )
                && 'INVESTMENT RETURNS'[Index] = minIndex
        )
    )
RETURN
    IF (
        'INVESTMENT RETURNS'[Index] > minIndex
            && firstValue < 0,
        CALCULATE (
            XIRR (
                'INVESTMENT RETURNS',
                'INVESTMENT RETURNS'[FREE CASHFLOW FOR PERIOD],
                'INVESTMENT RETURNS'[DATE]
            ),
            FILTER (
                ALL ( 'INVESTMENT RETURNS' ),
                EARLIER ( 'INVESTMENT RETURNS'[Index] ) >= 'INVESTMENT RETURNS'[Index]
                    && 'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] )
            )
        )
    )

 

Regards

Hi @v-ljerr-msft and @mjfigg 

 

I evaluated this post, and I think the solution would work for my purposes with one slight tweak that I can't seem to figure out.  My data is in a PBIX table that is CROSSJOINED, so has, out of necessity, blanks or 0 values and I think the XIRR function is having trouble because of the blanks.  

 

Link to sample excel data: https://www.dropbox.com/s/hc3qx9y9jvs4n4k/Rolling%20XIRR.xlsx?dl=0

 

Essentially my data looks like this (from Excel and the desired Rolling XIRR column, as calculated in Excel, is shown).  

 

 

Asset IDPeriodCash FlowMonthRolling IRR
X0-10004/30/2019 
X11305/31/2019 
X21306/30/2019-100.0%
X31307/31/2019-99.5%
X41308/31/2019-94.7%
X55259/30/201915.0%
X6 10/31/201915.0%
X7 11/30/201915.0%
X8 12/31/201915.0%
X9 1/31/202015.0%
Y0-20005/31/2019 
Y12506/30/2019 
Y22507/31/2019-100.0%
Y32508/31/2019-99.6%
Y42509/30/2019-95.6%
Y525010/31/2019-83.2%
Y625011/30/2019-61.4%
Y725012/31/2019-32.5%
Y82501/31/20200.0%
Y91252/29/202016.6%
Z0-15006/30/2019 
Z11757/31/2019 
Z21758/31/2019-100.0%
Z31759/30/2019-99.7%
Z417510/31/2019-96.6%
Z517511/30/2019-86.8%
Z617512/31/2019-68.8%
Z75501/31/202017.8%
Z8 2/29/202017.8%
Z9 3/31/202017.8%

Hey @mrothschild ,

 

I managed to get it working for you!

 

see file here: MJFIGG Updated file

 

What I did was just use my original code which has two key differences to yours:

  • Index - which I have found to be easier when using the EARLIER function, and 
  • Free Cashflow Capital - This is an optional column and is not strictly needed. For my purposes it was important because I needed to distinguish between Free Cashflow before Capital and potential capital payments. In your case I have just set this to 0 for all months. Essentially you now have two cashflow columns if you ever need it.

I could rewrite the code to remove the Free Cashflow Capital column, but I preferred to just get it finished for you. 

 

Hopefully this helps!!

 

All the best,

 

MJ

mrothschild
Continued Contributor
Continued Contributor

Thank you so much!

 

One question I have is that my actual table, as opposed to the sample data I posted, is calculated using CROSSJOIN, so doesn't actually show up in PowerQuery editor.  As a result, there's no easy way to create the Index column you used.  I'll search the forums for how to create this, but if you have any ideas without using PowerQuery, that would be the final piece.

 

Regardless, thanks again!

 

 

@mrothschild 

 

I updated the file again if you want to download it agin. I had a quick read online and it seems quite difficult to get an index in DAX rather than PowerQuery. I managed to come up with a very rough work around though for your case. Essentially arbitrarily allocating a greatly ascending value to your AssetID then multiplying that number by the period value. The result in this case being that each row has a unique value to it and then the RANK function can order them as an index would. 

 

This solution works now but may not work for every instance of data that you want to report on Smiley Frustrated. Only other thing I can suggest at the moment is to try and play around with your query so you can manipulate it in powerquery. Let me know if you need some help with that... 

 

All the best...

mrothschild
Continued Contributor
Continued Contributor

@mjfigg 

 

Really appreciate your help.  I tried to start with simple data and was triangulating to a solution as a result, but when I applied to the larger dataset, I'm getting an error that XIRR can't find a solution.  Again, I'm assuming it has to do with blank cells and I'm respectful of your time, so if this is overwhelming or I'm crazy to try to do this in its current form, let me know and I'll try a different path.  

 

Here's the link to the larger dataset that has your programming contained only changed by my attempt to create the calcualted DAX index.

https://www.dropbox.com/s/lo8m59ach4v3bf8/Rolling%20XIRR%20-%20new%20.pbix?dl=0

 

 

 

mrothschild
Continued Contributor
Continued Contributor

** Update ** 

I think what you did was this?

 

zzNew_Portfolio_Outputs[Period] + RANKX(zzNew_Portfolio_Outputs,zzNew_Portfolio_Outputs[Asset ID])

which creates an arbitrary index column.

 

 

Apologies and maybe I made a mistake, but the updated file (to me) looks like the original and I don't see a calculated index column or anything resembling RANK or transformation of Asset ID.  Again, error is likely mine, but I think I'm missing something significant.

 

 

Getting closer, but still have a grouping issue. 

 

Here's the link to the sampel PBIX file: https://www.dropbox.com/s/gkz6x35x7xg79xq/Rolling%20XIRR.pbix?dl=0

 

The following code provides a result, and I think it's something close to the Weighted Average XIRR by asset (weighted by Period 0 negative cash flow):  

 

zzXIRR 1 = 
CALCULATE(
    XIRR(GROUPBY(zzNew_Portfolio_Outputs,zzNew_Portfolio_Outputs[Asset ID],zzNew_Portfolio_Outputs[Cash Flow after Debt Service],zzNew_Portfolio_Outputs[Month]),
        zzNew_Portfolio_Outputs[Cash Flow after Debt Service],zzNew_Portfolio_Outputs[Month]),
        FILTER(zzNew_Portfolio_Outputs,NOT(ISBLANK(zzNew_Portfolio_Outputs[Cash Flow after Debt Service]))),
        FILTER(zzNew_Portfolio_Outputs,zzNew_Portfolio_Outputs[Month]<=
            CALCULATE(
                MAXX(GROUPBY(zzNew_Portfolio_Outputs,zzNew_Portfolio_Outputs[Asset ID],zzNew_Portfolio_Outputs[Month]),zzNew_Portfolio_Outputs[Month]),
                   FILTER(zzNew_Portfolio_Outputs,zzNew_Portfolio_Outputs[Asset ID]=EARLIER(zzNew_Portfolio_Outputs[Asset ID])
                )
            )
        )
        
)

 

The result from this formula is 16.72% but applies as a column to all three assets.  In excel, the WAVG is 16.65%.  

Hi @v-ljerr-msft,

 

Thank you very much for your help! 

 

The formula works great, although I have made a few tweaks to include:

 - a terminal value (from the [equity repayment/(investment) on sale] column) to be calculated at the end of each period and calculated in the XIRR calc (i.e. if I sold the investment now, what would my XIRR be), and

 - a check to ensure that there is at least one positive cashflow (another requirement of the XIRR formula along with the first periof being negative).

 

see my code as follows fyi.... 

ROLLING XIRR = 
VAR countpos =
    CALCULATE(
        COUNT('INVESTMENT RETURNS'[totalcashflow]),
            FILTER(ALL('INVESTMENT RETURNS'), 'INVESTMENT RETURNS'[totalcashflow]>0 && EARLIER ('INVESTMENT RETURNS'[Index] ) >= 'INVESTMENT RETURNS'[Index] && 'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] )
              )
           )

VAR minIndex =
    CALCULATE (
        MIN ( 'INVESTMENT RETURNS'[Index] ),
        FILTER (
            ALL ( 'INVESTMENT RETURNS' ),
            'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] )
        )
    )
VAR firstValue =
    CALCULATE (
        MIN ( 'INVESTMENT RETURNS'[FREE CASHFLOW FOR PERIOD (excl. sale)] ),
        FILTER (
            ALL ( 'INVESTMENT RETURNS' ),
            'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] )
                && 'INVESTMENT RETURNS'[Index] = minIndex
        )
    )
RETURN
    IF (
        'INVESTMENT RETURNS'[Index] > minIndex
            && firstValue < 0
            && countpos >= 1 ,
            XIRR (
                UNION( 
                    SUMMARIZE( 
                        FILTER(ALL ( 'INVESTMENT RETURNS' ), EARLIER ('INVESTMENT RETURNS'[Index] ) >= 'INVESTMENT RETURNS'[Index] && 'INVESTMENT RETURNS'[Name] = EARLIER ( 'INVESTMENT RETURNS'[Name] ))
                        ,'INVESTMENT RETURNS'[Index],
                        "DATE1",MAX('INVESTMENT RETURNS'[DATE]),
                        "CASHFLOW",MAX('INVESTMENT RETURNS'[FREE CASHFLOW FOR PERIOD (excl. sale)])
                            ),
                    SUMMARIZE(
                        FILTER(ALL ( 'INVESTMENT RETURNS' ), EARLIER ('INVESTMENT RETURNS'[Index] ) = 'INVESTMENT RETURNS'[Index] ),
                        'INVESTMENT RETURNS'[Index],
                        "DATE1",MAX('INVESTMENT RETURNS'[DATE]),
                        "CASHFLOW",MAX('INVESTMENT RETURNS'[EQUITY REPAYMENT/(INVESTMENT) ON SALE])
                            )
                ),
                [CASHFLOW],
                [DATE1]
            )
    )

Thanks again for all your help. Much appreciated.

 

MJ

 

 

DVA496
Frequent Visitor

Hi, 

 

I am trying to get the IRR (rolling or final) depending on a cutoff date which I included as a filter (different table containing all dates of my table). The cutoff date is a measure from a calcualted table which include calendar dates will 2050

S = SELECTEDVALUE(ValuationDate[Dates])


the table looks like this: there could be various assets and various value (entities)

DVA496_0-1696844323933.png


Hope you can help,

 

Best,

 

Dyana 

Is there a way to modify the code so that it works on Power Pivot as well?

We figured it out.  The code needs to be entered as a calculated column not a measure on both Power BI and Power Pivot 

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.