cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
common763
Helper II
Helper II

STDEV DAX when using row with value 1

I am trying to get the standard deviation to develop control charts.  I was able to calculate the SUM and AVG using the below formulas and both work perfectly.  The problem is my table is using a column called Number Of Issues Reported which always has a value of 1 in it.  This is making it difficult to produce the Standard Deviation because it is coming up 0 because all the values are 1 in the column.  Is there a way to get it to calculate the Standard Deviation properly similiar to what I did below for SUM and AVG?  I would prefer this to changing the SQL query since everything else works.  Below are the working formulas and the table layout. 

 

SUM = CALCULATE(SUMX(Table1, Table1[Number of Issues Reported]),
ALLSELECTED(Table1[Month]))
 
AVG = CALCULATE(SUMX(Table1, Table1[Number of Issues Reported])/DISTINCTCOUNT(Table1[Month]),
ALLSELECTED(Table1[Month]))
 
STDEV = CALCULATE(STDEVX.S(Table1, Table1[Number of Issues Reported]),
ALLSELECTED(FACTS[Month]))
NOT WORKING and I understand why but dont know how to tweak.  It is taking that 1 value and giving me a 0 StDev because all the rows have that 1. 
 
Sample table layout
MonthMajorNumber of Issues Reported
2020-1AAA1
2021-1BBB1
2019-2CCC1
2018-5AAA1
2020-2BBB1
2021-3CCC1
2022-3AAA1
2019-4BBB1
2018CCC1
 
1 ACCEPTED SOLUTION
Whitewater100
Super User
Super User

Hi:

Please see file. You willl notice I have summary table in and have set up a date table. I made up the data points but results appear to work as intended.  What do you think?

https://drive.google.com/file/d/1ibEFS6MXsidsA3ny7_KnDY-UAnJ0UOde/view?usp=sharing 

Whitewater100_0-1653576278798.png

 

View solution in original post

10 REPLIES 10
Whitewater100
Super User
Super User

Hi:

Please see file. You willl notice I have summary table in and have set up a date table. I made up the data points but results appear to work as intended.  What do you think?

https://drive.google.com/file/d/1ibEFS6MXsidsA3ny7_KnDY-UAnJ0UOde/view?usp=sharing 

Whitewater100_0-1653576278798.png

 

That would work perfectly if I wasnt trying to insert the STDEV into every column of month that the end-user selects.  I need that value in each column for month to develop the UCL and LCL.  I went in an rewrote the query and it looks like it now works ok so I can close this out.  Basically instead of having each row represent 1, I rewrote the query in SQL to group the totals.  I then was able to calculate the STDEV properly and then the UCL and LCL to get this functioning.  Thanks so much for taking the time to help me with this.  

I'm happy it is working for you with your extra touch! You are welcome! 

Whitewater100
Super User
Super User

Hi:

You could make a summary table and then do STD.P on a column after the results have been aggregated. But do you want STD on number of observations or maybe some other column. Your STD will be more useful if everything is always the same.

New Table:

Summary_Tble =ADDCOLUMNS(

                   SUMMARIZE(Table1, Table1[Month], Table1[Major]),

                  "No. Issues", SUM(Table1[Number of Issues Reported] )

 

Issues STD = = STDEV.P(Summary_Tble,Summary_Tble[No. Issues])
           

It could help you to have a Date Table all set up and record your fact table entries by date.

 

* Note on STD below:

STDEV.P assumes that the column refers to the entire population. If your data represents a sample of the population, then compute the standard deviation by using STDEV.S

 

I hope I have answered your question. Thanks..

       

I am trying your code out now and getting that dreaded "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value."  Assuming it is something in my setup of the table?  I have this linked from a SQL database and it is a stored procedure connected to multiple tables.  Probably not why this is happening but unsure.  I mirrored exactly what you had written so it has to be something on my end. 

Hi:

If the number of issues is always one/event than there can't be any STD becasuse everything is always one. Are you trying to get STD on monthly or weekly issues? Normally the STD would work something like this:

Test 1  - result 40

Test 2 - result 50

Test 3 - result  42

Sum = 132

Avg = 44

STD(pop) = 4.32

 

But when each result is one the STD = 0.

 

I hope my reply makes sense to you.

 

Thank you,

 

It does.  What I was hoping was to get the standard deviation from the sum of each month selected in the slicer.  So for instance if the end-user selects the below:

1-2020 with 1000

2-2020 with 2000

3-2020 with 1500

Then in simple form calculate the standard deviation of those three which would be STDEV(1000, 2000, 1500)

Hi:

Maybe your sample data isn't matching your latest example. I see 1 for Jan 2020 but you mention it is 1000? Do you have sample data to share? Just something to represent this issue so I can see those different totals. Thanks

Thanks for the response.  I will try your solution and respond in the am.  STDEV on Issues and have the STDEV calculate based off the end-users date selection.  My average and Sum works this way but see why the STDEV doesnt.  Again, will try what you suggested tomorrow morning.  Thanks again. 

Yes Sorry.  I am doing a poor job at explaining.  Below is a sample of the data layout and a quick pivot of what I want it to do.   

 

LAYOUT SAMPLE

MONTHMAJORISSUES
2022-2AAA1
2022-2BBB1
2022-3AAA1
2022-3BBB1
2022-4AAA1
2022-4BBB1
2022-5AAA1
2022-5BBB1
2022-2AAA1
2022-2BBB1
2022-3AAA1

 

 

LAYOUT AND CALC I need that Standard Dev to create Upper and Lower Control Limits for the chart. 

 

MAJOR2022-22022-32022-42022-5Grand Total
AAA255719
BBB356519
Grand Total510111238
      
STDEVIATION    
AAA1.26    
BBB1.89    

 

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors