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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
sinsai
New Member

Help with DAX Code to calculate "Maximum Drawdown" of Cumulative Return over time

Could you provide your DAX code or suggestions for calculating the 'Maximum Drawdown' of Cumulative Returns over time? I can easily perform this calculation in MS Excel (ColumnD), as an example, =MIN((C3-MAX($C$3:C3))/MAX($C$3:C3),0).

  • Dataset provided below. ColumnA and B are provided
  • ColumnC and D will need to be calculated dynamically. Examples below,
    • ColumnC: C10 = C9*(1+B10)
    • ColumnD: D10 = MIN( (C10 - MAX($C$3:C10) ) / MAX($C$3:C10), 0 )
  • Answer: MIN(ColumnD) will need to be returned to Power BI

I've tried asking 'ChatGPT'. The sample codes do not solve for the dynamic rolling window dataset, ie (C3 - MAX($C$3:C3)) and MAX($C$3:C3).

 

I can't attached the Excel file (as example).

 

Below is the code I've been working on,

------------------------------------

Maximum_Drawdown =
VAR PortIdSelected = SELECTCOLUMNS(port_return, port_return[Port_Id])
VAR MaxDate = MAXX(SELECTCOLUMNS(date_table, date_table[Date]), date_table[Date])

VAR CumulativeValue =
    PRODUCTX(
        FILTER(
            port_return,
            port_return[Date] <= MaxDate && port_return[Port_Id] = PortIdSelected
        ),
        1 + port_return[Total_Return_Value]
    ) - 1

VAR MaxValueUntilNow =
    MAXX(
        port_return,
        port_return[Cumulative_Total_Return_Value],
        TRUE
    )

VAR Drawdown = (port_return[Cumulative_Total_Return_Value] - MaxValueUntilNow) / MaxValueUntilNow

VAR MaxDraw =
    MINX(
        ALL(port_return[Cumulative_Total_Return_Value]),
        Drawdown
    )

RETURN MaxDraw
------------------------------------
 
MS Excel example,
sinsai_2-1744130768058.png

 

DateRate of ReturnCumulative ReturnMax DrawDown Calc
7/31/20060.009899191670522000001.009899191670520000000.00000000000000000000
8/31/20060.025532511901742400001.035684454801410000000.00000000000000000000
9/29/20060.015272008458347500001.051501436555320000000.00000000000000000000
10/31/20060.045669241565148700001.099522709667460000000.00000000000000000000
11/30/20060.034246323747269400001.137177320350210000000.00000000000000000000
12/29/20060.029581882870037800001.170817166643270000000.00000000000000000000
1/31/20070.017183096995414300001.190935431581600000000.00000000000000000000
2/28/2007-0.003653430479630850001.18658443177659000000-0.00365343047963093000
3/30/20070.026140303180112800001.217602108572030000000.00000000000000000000
4/30/20070.053393270924221300001.282613867832920000000.00000000000000000000
5/31/20070.034451255675869600001.326801526127050000000.00000000000000000000
6/29/2007-0.002783434344952430001.32310846119029000000-0.00278343434495238000
7/31/2007-0.023468463075009700001.29205713912461000000-0.02618657449381580000
8/31/2007-0.008515222195552900001.28105498549562000000-0.03447881218901340000
9/28/20070.037980226838212600001.329709744436960000000.00000000000000000000
10/31/20070.030988726910890600001.370915756578070000000.00000000000000000000
11/30/2007-0.053584502519094000001.29745591776625000000-0.05358450251909390000
12/31/2007-0.011809317281669900001.28213384917436000000-0.06476102340913540000
1/31/2008-0.067953206451595200001.19500874302284000000-0.12831351066699300000
2/29/2008-0.005011973220084290001.18901939120504000000-0.13268238000783900000
3/31/2008-0.013889578888760400001.17250441257063000000-0.14472905651233200000
4/30/20080.054671281523690500001.23660673139805000000-0.09797029798188570000
5/30/20080.014854754430286200001.25497622071981000000-0.08457086826958230000
6/30/2008-0.065899973993125600001.17227332041238000000-0.14489762424316600000
7/31/2008-0.039043833967325100001.12650327552588000000-0.17828409942728200000
8/29/2008-0.026855504986971500001.09625046119215000000-0.20035169489298600000
9/30/2008-0.136999959144227000000.94606419279698800000-0.30990348002239700000
10/31/2008-0.202596381805794000000.75439501038029900000-0.44971453806663000000
11/28/2008-0.066989870718642500000.70385818616413400000-0.48657809001989400000
12/31/20080.033290702445516000000.72729011960356400000-0.46948591398573800000
1/30/2009-0.083860931194190700000.66629889292527500000-0.51397531925052900000
2/27/2009-0.090683878963062600000.60587632476601700000-0.55804992257267500000
3/31/20090.085386088256269600000.65760973410487200000-0.52031353425660100000
4/30/20090.127487275281344000000.74144660730439200000-0.45915961374963700000
5/29/20090.102405863627099000000.81737508745878100000-0.40377438691125500000
6/30/2009-0.004168110617510430000.81396817767825500000-0.40625952121960100000
7/31/20090.089320571235313100000.88667228027584400000-0.35322628248940800000
8/31/20090.038852436756615200000.92112165896910500000-0.32809754753398700000
9/30/20090.048832391769488800000.96610223268724500000-0.29528694374428600000
10/30/2009-0.017693824850222600000.94900818899466800000-0.30775601313134000000
11/30/20090.040738265429329600000.98766913649254000000-0.27955519385242700000
12/31/20090.024316725226427800001.01168601549925000000-0.26203633546052900000
1/29/2010-0.043399577547801300000.96777926981556700000-0.29406364674717000000
2/26/20100.013062435675870200000.98042082427597300000-0.28484239854154600000
3/31/20100.067635939920272600001.04673250824329000000-0.23647204197577600000
4/30/20100.006558953139845560001.05359797771481000000-0.23146409787813300000
5/31/2010-0.094523710580164100000.95400798740144700000-0.30410896306076600000
6/30/2010-0.031916864971280300000.92355904328603200000-0.32631962332148000000
7/30/20100.081849933064544600000.99915228916014900000-0.27117892958344600000
8/31/2010-0.035711666986571900000.96347089534079100000-0.29720634494295800000
9/30/20100.099948114932261900001.05976799512220000000-0.22696344393365300000
10/29/20100.036907899889551300001.09888180619232000000-0.19843228811139200000
11/30/2010-0.019944002650398800001.07696570453715000000-0.21441875668177300000
12/31/20100.076082131598728800001.15890355099706000000-0.15465006114614200000
1/31/20110.014585077833473700001.17580624948984000000-0.14232056649143700000
2/28/20110.028036293306660900001.20877149837234000000-0.11827441433050000000
3/31/20110.002143734224921980001.21136278320351000000-0.11638422901551100000
4/29/20110.044097447969243500001.26478079050771000000-0.07741902852971930000
5/31/2011-0.020390597037873400001.23899115506722000000-0.09623100535377950000
6/30/2011-0.018720634680845100001.21579645428041000000-0.11315013453842600000
7/29/2011-0.018860927094712100001.19286540599422000000-0.12987694519485200000
8/31/2011-0.074765975659520900001.10367966008457000000-0.19493254433120200000
9/30/2011-0.097114937277414800000.99649587912110000000-0.27311661979256500000
10/31/20110.110427491920017000001.10653641976108000000-0.19284871119791400000
11/30/2011-0.033601994753974000001.06935458878918000000-0.21997060456990500000
12/30/2011-0.005356979438625120001.06362607824444000000-0.22414920600274700000

 

Desireable outcome, return the value in column Max Draw Down Calc (-0.55804992257267500000) for Date (2/27/2009)

 

Please assist if you can.

1 ACCEPTED SOLUTION
v-pgoloju
Community Support
Community Support

Hi @sinsai 

Thank you for reaching out to the Microsoft Fabric Forum Community.

Also, thanks to @lbendlin   for the prompt and helpful response.

You can try using the following DAX calculated columns:

CumulativeReturn =
VAR CurrentDate = drawdown[Date]
RETURN
CALCULATE (
PRODUCTX (
FILTER (
ALL (drawdown),
drawdown[Date] <= CurrentDate
),
1 + drawdown[RateOfReturn]
)
)


MaxCumulativeSoFar =
VAR CurrentDate = drawdown[Date]
RETURN
CALCULATE (
MAX (drawdown[CumulativeReturn]),
FILTER (
ALL (drawdown),
drawdown[Date] <= CurrentDate
)
)


and create measure:

Drawdown =
DIVIDE (
drawdown[CumulativeReturn] - drawdown[MaxCumulativeSoFar],
drawdown[MaxCumulativeSoFar],
0
)

I've attempted to reproduce the issue using the raw data. Kindly let me know if this solution works for you. If the issue still persists, please feel free to share more details so we can further investigate and help resolve it.


If you find this response helpful, please consider marking it as the accepted solution and giving it a thumbs-up to support others in the community.

Thank you!

View solution in original post

4 REPLIES 4
v-pgoloju
Community Support
Community Support

Hi @sinsai,

We wanted to kindly check in to see if everything is working as expected after trying the suggested solution. If there’s anything else we can assist with, please don’t hesitate to ask.

If the issue is resolved, we’d appreciate it if you could mark the helpful reply as Accepted Solution — it helps others who might face a similar issue.

 

Warm regards,

Prasanna Kumar

v-pgoloju
Community Support
Community Support

Hi @sinsai,

 

As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?

If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

 

Thanks & Regards,

Prasanna kumar

v-pgoloju
Community Support
Community Support

Hi @sinsai 

Thank you for reaching out to the Microsoft Fabric Forum Community.

Also, thanks to @lbendlin   for the prompt and helpful response.

You can try using the following DAX calculated columns:

CumulativeReturn =
VAR CurrentDate = drawdown[Date]
RETURN
CALCULATE (
PRODUCTX (
FILTER (
ALL (drawdown),
drawdown[Date] <= CurrentDate
),
1 + drawdown[RateOfReturn]
)
)


MaxCumulativeSoFar =
VAR CurrentDate = drawdown[Date]
RETURN
CALCULATE (
MAX (drawdown[CumulativeReturn]),
FILTER (
ALL (drawdown),
drawdown[Date] <= CurrentDate
)
)


and create measure:

Drawdown =
DIVIDE (
drawdown[CumulativeReturn] - drawdown[MaxCumulativeSoFar],
drawdown[MaxCumulativeSoFar],
0
)

I've attempted to reproduce the issue using the raw data. Kindly let me know if this solution works for you. If the issue still persists, please feel free to share more details so we can further investigate and help resolve it.


If you find this response helpful, please consider marking it as the accepted solution and giving it a thumbs-up to support others in the community.

Thank you!

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.