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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
vpatel55
Kudo Commander
Kudo Commander

Help needed with nested Iterator (STDEVX.P of a SUMMARIZED AVERAGEX)

I would like to produce the standard deviation of a virtual table produced by SUMMARIZE and AVERAGEX.

 

My AVERAGEX works fine. It sums up the daily sales for each weekday for the whole month, and then averages each weekday:

 

Average daily sales = 
AVERAGEX(
    SUMMARIZE (
        Sales,
        Sales[Date],
        Sales[Weekday],
        "Daily average", SUM (Sales[Units sold] )
    ),
    [Daily average]
)

 

 Here is the output:

 

vpatel55_0-1604081942991.png

 

I now need to write a DAX measure that calculates the standard deviation of this. I know that the function to use is STDEVX.P, but I don't know how to nest this. The answer should be 3.08, as it has been calculated in Excel:

 

vpatel55_1-1604082082118.png

 

Any help would be most appreciated on how I can create a measure that does this.  I have added the sample file here:

 

https://www.dropbox.com/s/6fl1wrzpqpe6wgi/Sample%20file.pbix?dl=0

1 ACCEPTED SOLUTION
MattAllington
Community Champion
Community Champion

Try this (courtesy of Mat Herring)

 

This seems to work
Measure =
STDEVX.P (
VALUES ( Sales[Weekday] ),
VAR TotalSales =
CALCULATE ( SUM ( Sales[Units sold] ) )
VAR Days =
CALCULATE ( DISTINCTCOUNT ( Sales[Date] ) )
RETURN
DIVIDE ( TotalSales, Days )
)



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

View solution in original post

3 REPLIES 3
MattAllington
Community Champion
Community Champion

Try this (courtesy of Mat Herring)

 

This seems to work
Measure =
STDEVX.P (
VALUES ( Sales[Weekday] ),
VAR TotalSales =
CALCULATE ( SUM ( Sales[Units sold] ) )
VAR Days =
CALCULATE ( DISTINCTCOUNT ( Sales[Date] ) )
RETURN
DIVIDE ( TotalSales, Days )
)



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Thanks @MattAllington and Mat Herring, I see you've thought about the problem in a different way and it works perfectly!

 

Big appreciation for this, and also your general work in the Power BI community.

No problem. It is very common for people, particularly people that come from a database background, to approach these problems by wanting to write a query. There are times when this is the right approach, but most often there is an easier way. The X functions are designed specifically to leverage lineage and table functions to do such calculations. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.