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
Panu_U
New Member

How to calculate Standard deviation with aggregated column and dynamic filters

Hello,

My apologies if this type of inquiry has already been posted and solved.

I tried to look for the solution and searched in the forum but I couldn't find it.

 

I would like to:

- Calculate Standard Deveiation (aggregated data by month)

- Return Standard Deviation to all rows

- Would like the calculation to be dynamic according to selected filters.

 

I tried many codes but it didn't seem to work.

For example, 

 
N_STD =
var group_month = summarize(Dim_Date,Dim_Date[Month-Year]"sum_by_month" , sum(volume_fact[Total_volume]))
var stdev = calculate(stdevx.P(group_month[sum_by_month]), allselected())
return(stdev)

 

The following is the example of the dataset:

Month-YearDepartmentProductVolume
2/1/2022ALREG            120,002
2/1/2022ALVIRTUAL            115,820
2/1/2022CAREG            230,142
2/1/2022CAVIRTUAL            105,874
3/1/2022ALREG            114,525
3/1/2022ALVIRTUAL            104,524
3/1/2022CAREG            235,741
3/1/2022CAVIRTUAL            121,025
4/1/2022ALREG            102,458
4/1/2022ALVIRTUAL            145,021
4/1/2022CAREG            211,021
4/1/2022CAVIRTUAL            114,528

 

I expect to display the information as below:

Month-YearVolumeSTD
2/1/2022                571,838                            1,667
3/1/2022                575,815                            1,667
4/1/2022                573,028                            1,667

 

If I select a filter (department = "AL"), I expect the calculation to be changed as below: 

Month-YearVolumeSTD
2/1/2022         235,822           11,669
3/1/2022         219,049           11,669
4/1/2022         247,479           11,669

 

Thank you in adavnce and I appreciate any help you could provide.

Thank you,

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @Panu_U ,

Here are the steps you can follow:

1. Create measure.

Measure =
var _select=SELECTEDVALUE('Table'[Department])
return
IF(
    HASONEVALUE('Table'[Department]),
SUMX(FILTER(ALL('Table'),
MONTH('Table'[Month-Year])=MONTH(MAX('Table'[Month-Year]))&&'Table'[Department]=_select),[Volume]),
SUMX(FILTER(ALL('Table'),
MONTH('Table'[Month-Year])=MONTH(MAX('Table'[Month-Year]))),[Volume]))
Measure 2 =
STDEVX.P(ALLSELECTED('Table'),[Measure])

2. Result:

vyangliumsft_0-1659667002986.png

If you need pbix, please click here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

2 REPLIES 2
v-yangliu-msft
Community Support
Community Support

Hi  @Panu_U ,

Here are the steps you can follow:

1. Create measure.

Measure =
var _select=SELECTEDVALUE('Table'[Department])
return
IF(
    HASONEVALUE('Table'[Department]),
SUMX(FILTER(ALL('Table'),
MONTH('Table'[Month-Year])=MONTH(MAX('Table'[Month-Year]))&&'Table'[Department]=_select),[Volume]),
SUMX(FILTER(ALL('Table'),
MONTH('Table'[Month-Year])=MONTH(MAX('Table'[Month-Year]))),[Volume]))
Measure 2 =
STDEVX.P(ALLSELECTED('Table'),[Measure])

2. Result:

vyangliumsft_0-1659667002986.png

If you need pbix, please click here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Hi Liu,

 

Thank you so much.

I really appreciate it.

 

Thank you,

Panu

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.