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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculate measure (standard deviation) based on selection

Hi power bi community,

 

currently I struggle with calculating a measure, based on the filter selection. My data looks like the following:

data.JPG

 

The complete power bi app can be found here.

 

I want to calculate the standard deviation of the revenue. In my case I want to know the standard deviation of every single country over all selected months.

revenue by month and country.JPG

Of course, dependend on what the user selects, the standard deviation has to be recalculated. The user might for example select only certain articles.

 

What I understand is, when using the available function stdev.p, the calculation is done not on the displayed and summed up values, but on every single row in the table which holds the data in the background. 

standard_deviation.JPG

I also tried everything with the stdevx.p function together with the allexcept function. As you can see the standard deviation is not calculated based on the values in the revenue column. The expected result is e.g. for Austria 314,22. As an example I calculated that in excel:

standard deviation in excel.JPG

 

Because of that "limitation" i tryed to calculate the standard deviation on my own with measures step by step. Meanwhile I'am sure, that this is nothing which is good and afterwards also maintainable. So, can please somebody support us in solving that problem? I'am sure there is a much better way or even just a simple solution for that.

 

Thank you very much in advance for you support.

 

Best regards,

 

Tom

1 ACCEPTED SOLUTION

Hi @Anonymous ,

>>I mean, it is a general problem for me to calculate something based on what there is shown in the power bi matrix.

In this scenario, we will need to use the measure rather than a calculated column, a calculated column will be calculated on whole data, the filter will not change it.

We can create a measure using the following DAX query:

STDEV1 = CALCULATE(STDEV.P(Tabelle1[Revenue]),FILTER(ALL(Tabelle1),Tabelle1[Country] = MIN(Tabelle1[Country]) && Tabelle1[Distinct Monat] in ALLSELECTED(Tabelle1[Distinct Monat])))

The result will like below: 

PBIDesktop_E71d7itkta.png

Best Regards,

Teige

View solution in original post

6 REPLIES 6
Gopal30
Helper I
Helper I

Meanwhile you can try the following formula as "Calculated Column" (Not Measure):

 

STDEV1 = CALCULATE(STDEV.S('Tabelle1'[Revenue]), FILTER('Tabelle1',('Tabelle1'[Country])=EARLIER('Tabelle1'[Country])),FILTER('Tabelle1',(Tabelle1[Distinct Monat]) = EARLIER('Tabelle1'[Distinct Monat])))
 
Check if it works
Anonymous
Not applicable

Hi Gopal30,

 

meanwhile I tryed your proposal. Unfortunately I had no success.

 

Here is what I did (it is a column - no measure):

trial1.JPG

 

Any other suggestion what I can do? I mean, it is a general problem for me to calculate something based on what there is shown in the power bi matrix. Average is another example where I want to calculate column total divided by number of rows within the matrix and show this in every row.

 

Anyway, thank you very much for your reply.

 

Best regards,

 

Tom

Hi @Anonymous ,

>>I mean, it is a general problem for me to calculate something based on what there is shown in the power bi matrix.

In this scenario, we will need to use the measure rather than a calculated column, a calculated column will be calculated on whole data, the filter will not change it.

We can create a measure using the following DAX query:

STDEV1 = CALCULATE(STDEV.P(Tabelle1[Revenue]),FILTER(ALL(Tabelle1),Tabelle1[Country] = MIN(Tabelle1[Country]) && Tabelle1[Distinct Monat] in ALLSELECTED(Tabelle1[Distinct Monat])))

The result will like below: 

PBIDesktop_E71d7itkta.png

Best Regards,

Teige

Anonymous
Not applicable

Hi @TeigeGao,

 

checking this post, I think have similar issue when it comes to add a standard deviation as a measure.

 

I have a pivot table with data coming from my data model, showing following data:

 

- Week numbers in columns [weeknum]

- Product ID in rows [Producto]

- Quantity consumed as Σ [Cantidad]

 

Point is, a lot of products have zero consumption along the year.

Here comes a screenshoot (week numbers reduced for pasting smaller picture):

 

malabar_0-1640709098278.png

 

What I want is to add a measure showing the total standard deviation as a column at the end based on column selection (eventually will be 52 weeks).

 

Can you advise?

 

Thanks,

Gopal30
Helper I
Helper I

Can you share the pbix file with sample data? 

Anonymous
Not applicable

Hi Gopal30,

 

thank you for your fast response. Please find the file here: https://ufile.io/eojbwrjt

 

 

Best regards,

 

Tom

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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