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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
RSip
Frequent Visitor

Standard deviation for custom number of grouped values in DAX

Hello guys,

 

I need to calculate standard deviation in every row for current rows value in column "Liters" and 4 rows below it while filtering by group. For example: first row is of group "A" and rank "8", so we take values coloured in magenta and if we calculate standard deviation in excel, it gives the answer 10.73. Those rows, which cannot form groups of 5, should remain 0 or null. "Standart deviation" is the column I am trying to achieve.

It seems like it should be an easy task, but I've been stuck on this for quite some time. I saw that a lot of people are suggesting just filtering in visuals, but i can not do that, because I will need these values to calculate further columns.

Since the information I am working with is confidential, I have created a dummy table:

Date:Liters:Group:Rank:Standard deviation:
2023-11-0831,12A810,73
2023-11-0734,44A714,15
2023-11-0742,89C812,46
2023-11-0544,51C712,56
2023-10-2121,89C612,58
2023-10-0629,56B620,33
2023-10-0332,59A612,20
2023-09-2057,21A512,59
2023-09-1551,11A40,00
2023-09-0940,03B519,07
2023-09-0161,13C56,43
2023-08-2721,15B40,00
2023-08-2442,82C40,00
2023-08-2380,15B30,00
2023-08-1770,16A30,00
2023-08-1556,61A20,00
2023-08-1343,58A10,00
2023-08-1047,78B20,00
2023-08-0548,81B10,00
2023-07-2546,56C30,00
2023-07-1445,53C20,00
2023-07-0151,13C10,00

 

Any suggestions would highly be appreaciated.

 

1 ACCEPTED SOLUTION
RSip
Frequent Visitor

Nevermind, I figured out the answer myself, used this formula:

TABLE = STDEVX.P(FILTER(TABLE,TABLE[GROUP]= EARLIER(TABLE[GROUP]) && EARLIER(TABLE[RANK])>= (TABLE[RANK])  && EARLIER(TABLE[RANK])<= (TABLE[RANK])+4),TABLE[LITERS]).
Formula grabs values from current row and 4 filtered rows below it, calculates standard deviation and returns scalar value.

View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

for current rows value in column "Liters" and 4 rows below it while filtering by group

Power BI has no such concept. You need to bring your own sort order.  Ideally your data already has an index column (or combination of columns) that can be used for that purpose.

 

Please clarify.

RSip
Frequent Visitor

What I described in an unclear way, was probably "Top N" function, as the top row should be the current row, and total rows returned should be 5. But I was unsuccessful in implementing this myself.

Every row is sorted, indexed and ranked in groups, I just need to find a way to filter them to get the desired results.

RSip
Frequent Visitor

Nevermind, I figured out the answer myself, used this formula:

TABLE = STDEVX.P(FILTER(TABLE,TABLE[GROUP]= EARLIER(TABLE[GROUP]) && EARLIER(TABLE[RANK])>= (TABLE[RANK])  && EARLIER(TABLE[RANK])<= (TABLE[RANK])+4),TABLE[LITERS]).
Formula grabs values from current row and 4 filtered rows below it, calculates standard deviation and returns scalar value.

Consider using WINDOW rather than EARLIER.

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors
Top Kudoed Authors