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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
vencenz
Regular Visitor

STDEV and VAR for Date Period

Hoping a kind soul could help with formula for calculating StDev and Variance of portfolio returns for a given trailing period (ie last 12-months or 3-years). I've tried using STDEV.P and defining the period with the 'CALCULATE' function but clearly this isn't working (same for variance):

 

StDEV_1 = CALCULATE (STDEV.P(return_table[Return]), DATESINPERIOD(return_table[Date], LASTDATE(return_table[Date]),-1, year), NOT(ISBLANK(return_table[Return])))

 

Portfolio NameDateReturn (Month)
Growth_Portfolio_A10/31/20171.88%
Growth_Portfolio_A9/30/20171.29%
Growth_Portfolio_A8/31/20170.47%
Growth_Portfolio_A7/31/20171.87%
Growth_Portfolio_A6/30/20172.79%
Growth_Portfolio_A5/31/20174.23%
Growth_Portfolio_A4/30/20173.72%
Growth_Portfolio_A3/31/20170.90%
Growth_Portfolio_A2/28/20173.67%
Growth_Portfolio_A1/31/20177.98%
Growth_Portfolio_A12/31/2016-0.26%
Growth_Portfolio_A11/30/20161.40%
Growth_Portfolio_A10/31/2016-4.02%
Growth_Portfolio_A9/30/20161.82%
Growth_Portfolio_A8/31/20161.60%
Growth_Portfolio_A7/31/20168.62%
Growth_Portfolio_A6/30/2016-2.66%
Growth_Portfolio_A5/31/20161.34%
Growth_Portfolio_A4/30/20160.23%
Growth_Portfolio_A3/31/20167.15%
Growth_Portfolio_A2/29/2016-1.56%
Growth_Portfolio_A1/31/2016-14.42%
Growth_Portfolio_A12/31/2015-1.67%
Growth_Portfolio_A11/30/20151.89%
Growth_Portfolio_A10/31/20156.80%
Growth_Portfolio_A9/30/2015-5.02%
Growth_Portfolio_A8/31/2015-8.30%
Growth_Portfolio_A7/31/20154.28%
Growth_Portfolio_A6/30/20151.04%
Growth_Portfolio_A5/31/20152.70%
Growth_Portfolio_A4/30/20153.03%
Growth_Portfolio_A3/31/2015-1.63%
Growth_Portfolio_A2/28/20155.88%
Growth_Portfolio_A1/31/2015-1.29%
Growth_Portfolio_A12/31/2014-2.53%
Growth_Portfolio_A11/30/2014-1.14%
Growth_Portfolio_A10/31/20141.66%
Growth_Portfolio_A9/30/2014-4.40%

 

Thank you!

1 ACCEPTED SOLUTION

Hi @vencenz,

 

Based on my test, the formula below should work in your scenario. Smiley Happy

StDEV_1 =
VAR year =
    YEAR ( MAX ( return_table[Date] ) )
RETURN
    CALCULATE (
        STDEV.P ( return_table[Return (Month)] ),
        FILTER (
            ALL ( return_table ),
            YEAR ( return_table[Date] )
                >= year - 1
                && NOT ( ISBLANK ( return_table[Return (Month)] ) )
        )
    )

Regards

View solution in original post

3 REPLIES 3
Greg_Deckler
Super User
Super User

Can you not just create a measure:

 

MyStdDev = STDEV.P([Return])

And then just use a Date slicer?

 

Or, if you really want to hard code it to TOTALYTD, use that function:

 

YtdStdDev = TOTALYTD(STDEV.P([Return]),Portfolio[Date])


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Thanks for the assistance! I need to be able to hard code because the display page is planned to show statistics based on returns for the trailing 1-, 3- and 5-year periods. Just can’t figure how to hard code the periods. Sorry if this is dumb question and I’m overlooking a simple solution

Hi @vencenz,

 

Based on my test, the formula below should work in your scenario. Smiley Happy

StDEV_1 =
VAR year =
    YEAR ( MAX ( return_table[Date] ) )
RETURN
    CALCULATE (
        STDEV.P ( return_table[Return (Month)] ),
        FILTER (
            ALL ( return_table ),
            YEAR ( return_table[Date] )
                >= year - 1
                && NOT ( ISBLANK ( return_table[Return (Month)] ) )
        )
    )

Regards

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.