Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Odassier
Frequent Visitor

Calculating Cumulative Returns from Daily Returns tables

I work in financial services and am new to Power BI (from Qlik). 

All of our data is in the form of a daily date column and daily returns for portfolios, benchmarks, stocks, etc. 

I would like to use Power BI as an interactive dashboard allowing the user to select custom date ranges and see the portfolio's cumulative returns in a line chart. This means the cumulative returns needs to be recomputed on the fly to show the starting date's return on day one and cumulative going forward.

 

I did see several posts in the forums with the subject "cumulative return" but their usecase was not a match and I could not (as a newbie) figure out how to adapt the DAX experssion for my purpose. 

 

Any help is greatly appreciated.

 

Olivier

 

 

11 REPLIES 11
johnt75
Super User
Super User

You could try

Cumul Total =
var minDate = MIN('Date'[Date])
var maxDate = MAX('Date'[Date])
return CALCULATE( SUM('Table'[Returns]), REMOVEFILTERS('Date'), 'Date'[Date] >= minDate && 'Date'[Date] <= maxDate)

@johnt75 

Thanks for getting back to me.

I just tried your expression but that gives me the same thing as the daily returns on the chart, it does not accumulate through time.

 

Thanks for the help though.

Replace the MIN('Date'[Date]) with CALCULATE( MIN('Date'[Date]), ALLSELECTED('Date'))

This is what I have now:

 

Cumm Total = var minDate = CALCULATE( MIN('Date'[Date]), ALLSELECTED('Date'))
var maxDate = MAX('Date'[Date])
return CALCULATE( SUM('MH-ALL'[Dividend Yield]), REMOVEFILTERS('Date'), 'Date'[Date] >= minDate && 'Date'[Date] <= maxDate)
 
Correct? That still gives me daily returns as before.

That looks correct to me. You are using a column from the Date table on your visual, not a column from the MH-ALL table?

Are there any other filters being applied, or any other relationships which could be impacting on the calculation?

So I have a date table which is associated wtih my Data table (MH-ALL) whcih also has a Date column. But I think the issue is that returns are not additive like Sales numbers etc. but are compounded through time which is why in other BI softwares, like Qlik or Tableu, the expression first converts daily returns into Log returns, then cummulates them (running total in BI speak), then converts the result into an exponent, as per my QLIK/Tableau expression below.

 

Olivier

Hi @Odassier ,

Please follow the below steps to get the culmulative values, you can get the details in the attachment.

1. Delete the relationship between the table 'MH-ALL' and 'Date'

yingyinr_0-1654757755516.png

2. Apply the date field of Date dimension table on X axis of your visual

3. Update the formula of measure [Cumm Total] as below

Cumm Total = 
CALCULATE (
    SUM ( 'MH-ALL'[Dividend Yield] ),
    FILTER (
        ALLSELECTED ( 'MH-ALL' ),
        'MH-ALL'[Date] <= SELECTEDVALUE ( 'Date'[Date] )
    )
)

yingyinr_1-1654757935277.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi all, 

I'm attaching the link to a sample pbix file here to help with this issue.

As you can see from the chart on the dashboard, there is a slight difference from the running total sum of daily returns and the cumulative return computed in excel. This comes from the fact that daily returns need to be counpounded over time and are not additive. 

If anyopne has a dashboard with a calculated measure for cumulative (investment) return, that could be great. 

 

File can be found here: https://www.dropbox.com/s/w6hdayywzl48wcf/SAP500_CumReturn.pbix?dl=0

 

Much obliged,

 

Olivier

Hi @v-yiruan-msft,

 

Thanks for this, it is very helpful. Unfortunately, this only works witjh data that is additive, like sales orders or goods sold etc. and which accrue over time. Financials returns compound over time and are not additive. So if you compute cumulative returns in excel you get slightly different values through time (see chart below with your additive formula in grey and the excel computed cumulative returns in orange. The longer the period, the more material the difference will be between the two methods. 

Odassier_0-1654760460629.png

Returns are not additive, but log returns are, which is why in the comments above I mention that in Qlik or Tableu the expressin we use first converts the daily returns data into log returns, then adds them through time, then takes the exponent of the final value to convert them back into returns. (e.g, exp(RangeSum(Above(log(1+([Dividend Yield]/100)), 0, RowNo()))) - 1.

 

So, what I need is a DAX expression that will do the following steps: 

  1. Compute y_t=log(1+r_t) where r_t is the return in period t.
  2. Compute running sum of y_t and call it z_t
  3. cumulative value at time t is then exp(z_t)

Does that make sense?

 

Thanks

 

Olivier

 

Ah, sorry, can't help with that

By way of help, the expression I used in Qlik (and Tableau) was: 

exp(RangeSum(Above(log(1+([daily return]/100)), 0, RowNo()))) - 1

I hope that helps. I need the equivalence in DAX.

Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.