Forum Discussion

rk_nithi's avatar
rk_nithi
Regular Visitor
8 months ago
Solved

XIRR calculation using DAX

Hello,

 

i need your support to calculate XIRR values of my mutual fund investment. I have a table as below

Date  Transaction AmountTransaction TypeInvestment Category
05-12-2019-10000BuyDebt
08-12-2019-90000BuyDebt
23-12-201950000SellDebt
14-01-202040000SellDebt
25-02-2020-10000BuyEquity
02-03-2020-50000BuyDebt
03-03-2020-5000BuyEquity
09-03-2020-2500BuyEquity
13-03-2020-2500BuyEquity
24-03-2020-2500BuyEquity
03-04-2020-2500BuyEquity
15-04-2020-11500BuyDebt
16-04-2020-6500BuyEquity
14-06-2020-232000BuyDebt
05-08-2020306027.52SellDebt
10-08-2020-99995BuyDebt
31-08-2020100142.49SellDebt
10-09-2020-99995BuyDebt
21-09-202025000SellDebt
11-01-202125000SellDebt
26-01-202150859.19SellDebt
03-02-20216.88SellDebt
02-03-2021-9999.5BuyEquity
31-03-2021-9999.5BuyEquity
05-04-2021-49997.5BuyEquity
07-04-2021-9999.5BuyEquity
12-04-2021-7999.6BuyEquity
28-04-2021-9999.5BuyEquity
07-05-2021-9999.5BuyEquity
28-05-2021-9999.5BuyEquity
08-06-2021-9999.5BuyEquity
28-06-2021-9999.5BuyEquity
07-07-2021-9999.5BuyEquity
27-07-2021-9999.5BuyEquity
09-08-2021-9999.5BuyEquity
16-11-202159160.07SellEquity
22-11-2021-24998.75BuyEquity
17-12-2021-9999.5BuyEquity
20-12-2021-9999.5BuyEquity
27-01-2022-4999.75BuyEquity
01-02-2022-9999.5BuyDebt
07-02-2022-4999.75BuyEquity
10-02-2022-4999.75BuyEquity
15-02-2022-24998.75BuyDebt
16-02-2022-4999.75BuyEquity
18-02-2022-24998.75BuyEquity
28-02-2022-4999.75BuyEquity
01-03-2022-9999.5BuyDebt
10-03-2022-4999.75BuyEquity

 

my question is how to calculate XIRR of my investments in the above format? also the current market value is not in the transaction table mentioend above and it is in different table. how to bring these tables together and calculate the XIRR value?

 

Thanks

10 Replies

  • Hii rk_nithi 

     

    Below are the exact items you must create:

    1. Create a Cashflow Column :
    Cashflow =
    IF(
        'Transactions'[Transaction Type] = "Buy",
        - 'Transactions'[Transaction Amount],
        'Transactions'[Transaction Amount]
    )

     

    1.  Create a Measure for Current Market Value
    CurrentValue_CF :=
    MAX('CurrentValue'[Current Value])

     

    1. Final_CF Column
    Final_CF = 'Transactions'[Cashflow]

     

    1. Create the XIRR Measure
    XIRR_Investment :=
    VAR CF =
        UNION(
            SELECTCOLUMNS(
                ALL('Transactions'),
                "Amount", 'Transactions'[Cashflow],
                "Date", 'Transactions'[Date]
            ),
            ROW(
                "Amount", [CurrentValue_CF],
                "Date", TODAY()
            )
        )
    RETURN
    IF(
        HASONEVALUE('Transactions'[Date]),
        BLANK(),       
        XIRR(CF, [Amount], [Date]) 
    )

     

     

  • Hi rk_nithi ,

    according to the definition of the XIRR function (XIRR( CashFlows, [Payment], [Date] )) I would try:

    XIRR(Your Table Name, [Transaction Amount], [Date])

    Did you already try that?

    What do you want to do with the "current market value"?

    • rk_nithi's avatar
      rk_nithi
      Regular Visitor

      Hi DNMAF,
      Thanks for the reply, in my table only transactions of bought and sold details are available and you know the value of previous investments would change as per per market value. So the current value of total investments would be different than the invested amount. to calculate overall return on investment , i think we should calculate difference between current market value and invested value right? my question is in the XIRR formula there is no possibility to consider current market value, how to accommodate that?

      • Hans-Georg_Puls's avatar
        Hans-Georg_Puls
        Super User

        Hi rk_nithi ,

         

        to include the current market value you could do the following (assuming that the current market values are positive and the table with the market values has a date column):

         

        1. Create a table with all relevant values using UNION: (your column and table names might be different)
          All Values = UNION(SELECTCOLUMNS('Market Value', "Date", [Date], "Value", [Market Value]), SELECTCOLUMNS('Transaction', "Date", [Date], "Value", [Transaction Amount]))
        2. Define an appropriate measure like the following:
          XIRR with market values =
          VAR MinDate = CALCULATE(MIN('All Values'[Date]), REMOVEFILTERS('All Values'))
          VAR MaxDate = SELECTEDVALUE('All Values'[Date], MAX('All Values'[Date]))
          RETURN
              CALCULATE(
                  XIRR( 'All Values', [Value], [Date],, BLANK()),
                  REMOVEFILTERS('All Values'),
                  'All Values'[Date] >= MinDate && 'All Values'[Date] <= MaxDate
              )

        Does that fulfil your requirements?

  • Ohouot225's avatar
    Ohouot225
    Frequent Visitor

    • Split the columns:

                 Make sure that the
    Transaction Amount

        and

    Date

      are in separate columns. If this hasn’t been done yet, you’ll need to separate them properly in Power Query.
    1. Align the column structure: Ensure that both tables (transactions and current market value) have the same columns, in the same order, with consistent names.
    2. Append the tables: Use the Append Queries option in Power Query to merge the two tables into a single table containing all cash flows.
    3. Calculate the XIRR: Once the unified table is ready, you can apply the DAX function XIRR() to compute the extended internal rate of return based on the Cash Flow and Date columns.

     

     

  • Ohouot225's avatar
    Ohouot225
    Frequent Visitor

    This is my proposition:

    Create a single table in Power Query.

    1. Transform the actual value to get a Table like that:

     

    DateTransaction Type

    Cashflow

    20/11/2025Overall Portfolio95.000

     

    •      Add a custom column with this script 
    DateTime.LocalNow()​
    • Name the column Date and move at the first column.
    • Change the name 'Portfolio' to 'Transaction Type' and 'Current Value' to 'Cashflow', and ensure that the column order follows the same sequence as in the transaction table.

     

    For the transaction Table, you will have something like this:

     

     

    •   Begin by adding a conditional column for the Cashflow
    •   The Append in Power Query to add the Actual value to the Transaction Table (Check the order of the columns before)

     

    Now you can easily use the XIIR function with both table

    XIRR_Investment = 
    XIRR(Transactions, Transactions[Cashflow], Transactions[Date])

     

     

    NB: The data I use may differ from yours.

     

    • v-menakakota's avatar
      v-menakakota
      Community Support

      Hi rk_nithi ,

      Thanks for reaching out to the Microsoft fabric community forum. 

       

      I would also take a moment to thank Ohouot225   , for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.

      I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We’re always here to support you 

       

      Best Regards, 
      Community Support Team