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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
TMO_KY
Helper II
Helper II

Adjusting rolling Z-Score for new items

Good Morning Community,

 

so I have a report that calculates rolling Z-Scores month to month, in order to do that, I have other rolling measures, thanks to this community, I found most of my answers/coding.  For example, we trend codes and calculate the Z-Score over the previous 24 months of code usage.  This is great for codes that have been used for a while, works perfectly.  However, the one problem I'm running into now is when something new is added, it throws the Z-Score way above our "breach" line.  Last month we introduced 4 new codes, so because of that, I have a DAX table that will automatically add missing values to whatever months are missing (this is a necessity, explained below), so for the 4 new codes, the last 23 months are all 0's.  My measures are working the way they were intended but now my Z-Score is way off. 

So long story short is there a way in DAX to have measures exclude if X number rows  = 0 and then return 0 for the Z-score.  Kind of like an IF statement until we get above a threshold to start including the actual calculation?

 

z = (x – μ) / σ

z = standard score

x = Current Month Value

μ = Population Mean Value (previous 24 months)

σ = standard deviation

 

Here's an example of the new code being used.

CodeAmt MonthAvg 24 mStd Dev 24mZ-Score
BC07808/01/20220.331.604.80
BC07007/01/2022   
BC07006/01/2022   
BC07005/01/2022   
BC07004/01/2022   
BC07003/01/2022   
BC07002/01/2022   
BC07001/01/2022   
BC07012/01/2021   
BC07011/01/2021   
BC07010/01/2021   
BC07009/01/2021   
BC07008/01/2021   
BC07007/01/2021   
BC07006/01/2021   
BC07005/01/2021   
BC07004/01/2021   
BC07003/01/2021   
BC07002/01/2021   
BC07001/01/2021   
BC07012/01/2020   
BC07011/01/2020   
BC07010/01/2020   
BC07009/01/2020   
BC07008/01/2020   
BC07007/01/2020   
BC07006/01/2020   
BC07005/01/2020   
BC07004/01/2020   
BC07003/01/2020   
BC07002/01/2020   
BC07001/01/2020   
BC07012/01/2019   
BC07011/01/2019   
BC07010/01/2019   
BC07009/01/2019   
BC07008/01/2019   

 

Here's an example of a working code, also shows why I had to insert 0 when a code wasn't used to get the correct Z-Score for the previous 24 months.  This particular code wasn't used for 4 months in a row BUT I needed to show that to get an accurate Avg/Std Deviation and Z-Score.

CodeAmt MonthAvg 24 mStd Dev 24mZ-ScorePrev Month
KP01108/01/20222.086.36-0.171
KP01207/01/2022    
KP01206/01/2022    
KP01205/01/2022    
KP01504/01/2022    
KP01003/01/2022    
KP01002/01/2022    
KP01001/01/2022    
KP01012/01/2021    
KP01111/01/2021    
KP01010/01/2021    
KP01009/01/2021    
KP01008/01/2021    
KP01007/01/2021    
KP01106/01/2021    
KP01305/01/2021    
KP01104/01/2021    
KP01003/01/2021    
KP01002/01/2021    
KP01001/01/2021    
KP01012/01/2020    
KP01011/01/2020    
KP01010/01/2020    
KP013209/01/2020    
KP012608/01/2020    
KP01207/01/2020    
KP01206/01/2020    
KP01005/01/2020    
KP01204/01/2020    
KP01103/01/2020    
KP01002/01/2020    
KP01101/01/2020    
KP01312/01/2019    
KP01011/01/2019    
KP01010/01/2019    
KP01009/01/2019    
KP01008/01/2019    
1 ACCEPTED SOLUTION

Thank you for the reply but I ended up figuring out a way to do it.  I ended up creating an index column on my table using the most recent date as index 1 per category[Code] then created a variable to compare the mostrecent [AMT] to the sum of previous 24 months and if it equals, return 0 otherwise return "z":

 

 

testZ-Score = 
VAR z = ( [_testPrev Month] - [_TEST24m moving average] ) / [_testStDv of last 24 months]
var a = IF(CALCULATE(SUM(table2[Amt]),FILTER(table2,table2[index]=1)) = [sumPrev24],0,z)
RETURN
    IFERROR ( a, BLANK () )

 

 

 Here was my output, expected results vs what I was getting:

CodeindexAmtsumPrev24Original (Not Correct)testZ-Score (expected results)
AI0112191.61.6
BC071884.80

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @TMO_KY ,

 

It would be great if you could provide more information to describe this problem.

I don't quite understand what your specific needs are and whether you can provide an output that you expect.

 

Best Regards,

Neeko Tang

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

 

Thank you for the reply but I ended up figuring out a way to do it.  I ended up creating an index column on my table using the most recent date as index 1 per category[Code] then created a variable to compare the mostrecent [AMT] to the sum of previous 24 months and if it equals, return 0 otherwise return "z":

 

 

testZ-Score = 
VAR z = ( [_testPrev Month] - [_TEST24m moving average] ) / [_testStDv of last 24 months]
var a = IF(CALCULATE(SUM(table2[Amt]),FILTER(table2,table2[index]=1)) = [sumPrev24],0,z)
RETURN
    IFERROR ( a, BLANK () )

 

 

 Here was my output, expected results vs what I was getting:

CodeindexAmtsumPrev24Original (Not Correct)testZ-Score (expected results)
AI0112191.61.6
BC071884.80

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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