I finished my Fundamental Finance Accounting course last week. I learned 2 awesome functions which helps which which projects to undertaken. Frist is NPV net present value and the second is IRR(Internal Rate of Return). I found those two are so powerful to use helping to decide which investment to choice so I want to implement in DAX. Fortunately, in DAX there are two functions XNPV and XIRR which I can choose to use. I found that XNPV and XIRR are also in excel and would be a replacement of IRR and NPV. They have slightly different calculation details but the purpose are the same. You can find http://www.differencebetween.net/business/finance-business-2/difference-between-npv-and-xnpv/ and https://corporatefinanceinstitute.com/resources/knowledge/modeling/xirr-vs-irr-excel-financial-model/ for more details.

The Excel **XNPV** function is a financial function that calculates the net present value (NPV) of an investment using a discount rate and a series of cash flows that occur at irregular intervals. Calculate net present value for irregular cash flows. Net present value. =**XNPV** (rate, values, dates)

The Excek XIRR(Internal Rate of Return) is the discount rate which sets the Net Present Value (XNPV) of all future cash flow of an investment to zero. If the NPV of an investment is zero it doesn’t mean it’s a good or bad investment, it just means you will earn the IRR (discount rate) as your rate of return. =XIRR(values,dates,guess)

The challenge in DAX, I found, is that , we may not have the date field. For example, we may just calculate a intial investiment and an estimate assuming paying amount every year or every month in the future. Something like this:

So in DAX, we can create table variable in the Measure to leverage XIRR and XNVP.

XIRR = VAR cashflowtable = UNION ( GENERATE ( GENERATESERIES ( YEAR ( NOW () ), YEAR ( NOW () ) ), VAR inc = [Value] RETURN ROW ( "date", DATE ( inc, 1, 1 ), "Values", SUM ( 'Considered Project'[Initial Inventestment] ) ) ), GENERATE ( GENERATESERIES ( YEAR ( NOW () ) + 1, YEAR ( NOW () ) + [Investment Years] ), VAR inc = [Value] RETURN ROW ( "date", DATE ( inc, 1, 1 ), "Values", SUM ( 'Considered Project'[Annual Cash flow] ) ) ), GENERATE ( GENERATESERIES ( YEAR ( NOW () ) + [Investment Years], YEAR ( NOW () ) + [Investment Years] ), VAR inc = [Value] RETURN ROW ( "date", DATE ( inc, 1, 1 ), "Values", SUM ( 'Considered Project'[Exit Value] ) ) ) ) RETURN XIRR ( cashflowtable, [Values], [date] )

```
XNVP =
VAR cashflowtable =
UNION (
GENERATE (
GENERATESERIES ( YEAR ( NOW () ), YEAR ( NOW () ) ),
VAR inc = [Value]
RETURN
ROW (
"date", DATE ( inc, 1, 1 ),
"Values", SUM ( 'Considered Project'[Initial Inventestment] )
)
),
GENERATE (
GENERATESERIES ( YEAR ( NOW () ) + 1, YEAR ( NOW () ) + [Investment Years] ),
VAR inc = [Value]
RETURN
ROW (
"date", DATE ( inc, 1, 1 ),
"Values", SUM ( 'Considered Project'[Annual Cash flow] )
)
),
GENERATE (
GENERATESERIES (
YEAR ( NOW () ) + [Investment Years],
YEAR ( NOW () ) + [Investment Years]
),
VAR inc = [Value]
RETURN
ROW (
"date", DATE ( inc, 1, 1 ),
"Values", SUM ( 'Considered Project'[Exit Value] )
)
)
)
RETURN
XNPV ( cashflowtable, [Values], [date], [Interest Rate] )
```

Hopefully, you find this helpful.

Thanks,

your friend, Annie