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
kirbynguyen
Helper II
Helper II

Standard Deviation DAX

Hello,

 

I am trying to calculate standard deviation from my data:

 

ProductProfitCount

Total

11005500
12004800
13003900
14001400
21007700
22003600

 

Total = Profit * Count. I am trying to calculate the standard deviation per product using the Total column as the value and the Count column as the counts. I was able to create a calculated column for mean:

 

Mean = CALCULATE(SUM(total) / SUM(count), ALLEXCEPT(table, product))

 

The DAX for STDEV doesn't seem to work for me as I was getting an extemely large number. Please help me find the correct way to calculate the standard deviation.

 

Thanks in advance!

1 ACCEPTED SOLUTION

@smpa01  @Greg_Deckler 

 

Well, I think I figured it out. Here's the solution:

kirbynguyen_0-1612210156401.png

 
prodtop = POWER('Table'[Profit] - 'Table'[prodmean], 2) * 'Table'[Count]
prodtoptotal = CALCULATE(SUM('Table'[prodtop]), ALLEXCEPT('Table', 'Table'[Product]))
variance = 'Table'[prodtoptotal] / 'Table'[prodcount]
std = SQRT('Table'[variance])
 
I think I can consolidate this into fewer columns so I'll work on that. Thanks for the help 😁

View solution in original post

8 REPLIES 8
Greg_Deckler
Community Champion
Community Champion

@kirbynguyen What number are you expecting? The default Standard Deviation aggregation seems correct to me.

Greg_Deckler_0-1612206976765.png

 



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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

I've calculated the Standard Deviations by hand and I got 96.0769 for product 1 and 45.8258 for product 2.

But this is the result when I used the STDEV functions:

kirbynguyen_0-1612207668678.png

kirbynguyen_1-1612207708976.png

This is because it doesn't take into account the total counts and I couldn't figure out a way to include it.

 

@kirbynguyencan you show the formula that you used to arrive on 96.0769 for product 1 and 45.8258 for product 2

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@kirbynguyen  DAX is working as expected

Capture.PNG

 

once your dataset is like this

Capture.PNG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

@smpa01 

Well, the dataset was just a sample. I don't want to pivot my data since the counts are very high and there are more filters than just "product". Thanks for the input though!

@smpa01  @Greg_Deckler 

 

Well, I think I figured it out. Here's the solution:

kirbynguyen_0-1612210156401.png

 
prodtop = POWER('Table'[Profit] - 'Table'[prodmean], 2) * 'Table'[Count]
prodtoptotal = CALCULATE(SUM('Table'[prodtop]), ALLEXCEPT('Table', 'Table'[Product]))
variance = 'Table'[prodtoptotal] / 'Table'[prodcount]
std = SQRT('Table'[variance])
 
I think I can consolidate this into fewer columns so I'll work on that. Thanks for the help 😁
smpa01
Super User
Super User

@kirbynguyen  were you hoping for this

_total:= CALCULATE(SUMX('Table 1','Table 1'[Total]),ALLEXCEPT('Table 1','Table 1'[Product]))
_count:= CALCULATE(SUMX('Table 1','Table 1'[Count]),ALLEXCEPT('Table 1','Table 1'[Product]))
_mean:= DIVIDE([_total],[_count])
_sq:= (MAX('Table 1'[Total])-[_mean])^2
_sumsq:= CALCULATE(SUMX('Table 1',[_sq]),ALLEXCEPT('Table 1','Table 1'[Product]))
STDEV:= SQRT(DIVIDE([_sumsq],[_count]))

Capture.PNG

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.