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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
bhdben
New Member

Cumulative measure that resets on a specific value

Hi, 

I hope you are doing well.

I am trying to write a measure that will increase by one each time a condition is met and then reset to zero if another one is met. the measure is based off the QA Grade, and shoudl increase by one anythime it encounters "Unaceptable". This measure should reset back to zero when QA Grade is anything but "Unacceptable". This is the data for one property, but i want to use the measure in a matrix that has about 20 properties. The matrix shoudl show the value based on the most recentt evaluation date, and this is my only table. Ive tried to create a bool based on the QA Grade, but havent had luck making that work either. Any help is greatly appreciated 

 

PropertyEvaluation TypeEvaluation DateQA ScoreQA GradeSALT GradePIP GradeBrand Standards ScoreCleanliness ScoreCondition Score
placeFollow-up2/16/202460.47%UnacceptableUnacceptableFail79.84%94.31%65.59%
placeFollow-up6/20/202351.76%UnacceptableAcceptableFail44.05%92.89%59.29%
placeProgress10/20/202280.57%ProgressUnacceptablePass100.00%95.57%75.27%
placeFollow-up2/18/202255.22%UnacceptableAcceptableFail35.98%96.43%74.90%
placeVirtual3/5/202180.24%VirtualVirtualVirtual91.20%95.27%81.27%
placeVirtual10/19/202081.79%VirtualVirtualVirtual97.48%95.27%81.69%
placeRegular3/3/202079.3%AcceptableOutstandingPass87.4%95.1%81.3%
placeProgress4/5/201994.96%ProgressAcceptablePass97.90%96.53%91.44%
placeProgress7/20/201883.92%ProgressAcceptable 93.72%88.22%88.18%
placeRegular10/5/201796.73%OutstandingOutstanding 100.00%97.20%94.09%
placeRegular4/21/201783.49%AcceptableAcceptable 96.23%86.26%87.40%
placeRegular7/29/201698.17%OutstandingOutstanding 100.00%98.91%96.21%
placeRegular2/4/201684.61%AcceptableAcceptable 87.40%99.24%93.23%
placeCourtesy8/19/201581.53%CourtesyOutstanding 100.00%99.57%75.35%
          
1 ACCEPTED SOLUTION
SachinNandanwar
Super User
Super User

First create a measure in the main table _t :

 

 

Cnt = 
VAR _Dt =
    MAX ( _t[Evaluation Date] )
VAR _Tbl =
    FILTER ( _t, _t[Evaluation Date] <= _Dt )
VAR _cnt =
    COUNTROWS ( FILTER ( _Tbl, [QA Grade] = "Unacceptable" ) )
RETURN
    IF ( MAX ( _t[QA Grade] ) = "Unacceptable", _cnt, 0 )

 

 

 Then create a Calculated table _t_final :

 

 

_t_final = 
SUMMARIZE (
    _t,
    _t[QA Grade],
    _t[Brand Standards Score],
    _t[Cleanliness Score],
    _t[Condition Score],
    _t[Evaluation Date],
    _t[Evaluation Type],
    _t[PIP Grade],
    _t[Property],
    _t[QA Score],
    _t[SALT Grade],
    "Cnt", _t[Cnt]
)

 

Then create a column "Unacceptable_Series" on this table to get the final series:

 

Unacceptable_Series = 
VAR _currentValue = '_t_final'[Cnt]
VAR _currentDate = '_t_final'[Evaluation Date]
     
VAR _last_0 = 
CALCULATE ( 
    MAX ('_t_final'[Evaluation Date] ), 
    FILTER('_t_final', '_t_final'[Evaluation Date] < _currentDate && '_t_final'[Cnt] = 0)
)

RETURN 
IF ( 
    _currentValue = 0, 
    0, 
    CALCULATE(SUM(_t_final[Cnt]),ALLEXCEPT(_t_final,_t_final[Property]),_t_final[Evaluation 
    Date]<=_currentDate &&'_t_final'[Evaluation Date] >= _last_0
   
))

 

SachinNandanwar_0-1729122119026.png
I added a few additional rows to ensure that i get the output correct

 

>>Sample Data
Property,Evaluation Type,Evaluation Date,QA Score,QA Grade,SALT Grade,PIP Grade,Brand Standards Score,Cleanliness Score,Condition Score
place,Follow-up,2/16/2024,60.47%,Unacceptable,Unacceptable,Fail,79.84%,94.31%,65.59%
place,Follow-up,3/16/2024,60.47%,Unacceptable,Unacceptable,Fail,89.84%,98.31%,55.59%
place,Follow-up,6/20/2023,51.76%,Unacceptable,Acceptable,Fail,44.05%,92.89%,59.29%
place,Progress,10/20/2022,80.57%,Progress,Unacceptable,Pass,100.00%,95.57%,75.27%
place,Follow-up,2/18/2022,55.22%,Unacceptable,Acceptable,Fail,35.98%,96.43%,74.90%
place,Virtual,3/5/2021,80.24%,Virtual,Virtual,Virtual,91.20%,95.27%,81.27%
place,Virtual,10/19/2020,81.79%,Virtual,Virtual,Virtual,97.48%,95.27%,81.69%
place,Regular,3/3/2020,79.3%,Acceptable,Outstanding,Pass,87.4%,95.1%,81.3%
place,Progress,4/5/2019,94.96%,Progress,Acceptable,Pass,97.90%,96.53%,91.44%
place,Progress,7/20/2018,83.92%,Progress,Acceptable,,93.72%,88.22%,88.18%
place,Regular,10/5/2017,96.73%,Outstanding,Outstanding,,100.00%,97.20%,94.09%
place,Regular,4/21/2017,83.49%,Unacceptable,Acceptable,,96.23%,86.26%,87.40%
place,Regular,7/29/2016,98.17%,Outstanding,Outstanding,,100.00%,98.91%,96.21%
place,Regular,2/4/2016,84.61%,Acceptable,Acceptable,,87.40%,99.24%,93.23%
place,Courtesy,8/19/2015,81.53%,Courtesy,Outstanding,,100.00%,99.57%,75.35%
place,Courtesy,4/16/2024,81.53%,Courtesy,Outstanding,,100.00%,99.57%,75.35%
place,Courtesy,5/16/2024,81.53%,Courtesy,Outstanding,,100.00%,99.57%,75.35%
place,Follow-up,6/16/2024,60.47%,Unacceptable,Unacceptable,Fail,89.84%,98.31%,55.59%
place,Follow-up,7/20/2023,51.76%,Unacceptable,Acceptable,Fail,44.05%,92.89%,59.29%



Regards,
Sachin
Check out my Blog

View solution in original post

4 REPLIES 4
SachinNandanwar
Super User
Super User

First create a measure in the main table _t :

 

 

Cnt = 
VAR _Dt =
    MAX ( _t[Evaluation Date] )
VAR _Tbl =
    FILTER ( _t, _t[Evaluation Date] <= _Dt )
VAR _cnt =
    COUNTROWS ( FILTER ( _Tbl, [QA Grade] = "Unacceptable" ) )
RETURN
    IF ( MAX ( _t[QA Grade] ) = "Unacceptable", _cnt, 0 )

 

 

 Then create a Calculated table _t_final :

 

 

_t_final = 
SUMMARIZE (
    _t,
    _t[QA Grade],
    _t[Brand Standards Score],
    _t[Cleanliness Score],
    _t[Condition Score],
    _t[Evaluation Date],
    _t[Evaluation Type],
    _t[PIP Grade],
    _t[Property],
    _t[QA Score],
    _t[SALT Grade],
    "Cnt", _t[Cnt]
)

 

Then create a column "Unacceptable_Series" on this table to get the final series:

 

Unacceptable_Series = 
VAR _currentValue = '_t_final'[Cnt]
VAR _currentDate = '_t_final'[Evaluation Date]
     
VAR _last_0 = 
CALCULATE ( 
    MAX ('_t_final'[Evaluation Date] ), 
    FILTER('_t_final', '_t_final'[Evaluation Date] < _currentDate && '_t_final'[Cnt] = 0)
)

RETURN 
IF ( 
    _currentValue = 0, 
    0, 
    CALCULATE(SUM(_t_final[Cnt]),ALLEXCEPT(_t_final,_t_final[Property]),_t_final[Evaluation 
    Date]<=_currentDate &&'_t_final'[Evaluation Date] >= _last_0
   
))

 

SachinNandanwar_0-1729122119026.png
I added a few additional rows to ensure that i get the output correct

 

>>Sample Data
Property,Evaluation Type,Evaluation Date,QA Score,QA Grade,SALT Grade,PIP Grade,Brand Standards Score,Cleanliness Score,Condition Score
place,Follow-up,2/16/2024,60.47%,Unacceptable,Unacceptable,Fail,79.84%,94.31%,65.59%
place,Follow-up,3/16/2024,60.47%,Unacceptable,Unacceptable,Fail,89.84%,98.31%,55.59%
place,Follow-up,6/20/2023,51.76%,Unacceptable,Acceptable,Fail,44.05%,92.89%,59.29%
place,Progress,10/20/2022,80.57%,Progress,Unacceptable,Pass,100.00%,95.57%,75.27%
place,Follow-up,2/18/2022,55.22%,Unacceptable,Acceptable,Fail,35.98%,96.43%,74.90%
place,Virtual,3/5/2021,80.24%,Virtual,Virtual,Virtual,91.20%,95.27%,81.27%
place,Virtual,10/19/2020,81.79%,Virtual,Virtual,Virtual,97.48%,95.27%,81.69%
place,Regular,3/3/2020,79.3%,Acceptable,Outstanding,Pass,87.4%,95.1%,81.3%
place,Progress,4/5/2019,94.96%,Progress,Acceptable,Pass,97.90%,96.53%,91.44%
place,Progress,7/20/2018,83.92%,Progress,Acceptable,,93.72%,88.22%,88.18%
place,Regular,10/5/2017,96.73%,Outstanding,Outstanding,,100.00%,97.20%,94.09%
place,Regular,4/21/2017,83.49%,Unacceptable,Acceptable,,96.23%,86.26%,87.40%
place,Regular,7/29/2016,98.17%,Outstanding,Outstanding,,100.00%,98.91%,96.21%
place,Regular,2/4/2016,84.61%,Acceptable,Acceptable,,87.40%,99.24%,93.23%
place,Courtesy,8/19/2015,81.53%,Courtesy,Outstanding,,100.00%,99.57%,75.35%
place,Courtesy,4/16/2024,81.53%,Courtesy,Outstanding,,100.00%,99.57%,75.35%
place,Courtesy,5/16/2024,81.53%,Courtesy,Outstanding,,100.00%,99.57%,75.35%
place,Follow-up,6/16/2024,60.47%,Unacceptable,Unacceptable,Fail,89.84%,98.31%,55.59%
place,Follow-up,7/20/2023,51.76%,Unacceptable,Acceptable,Fail,44.05%,92.89%,59.29%



Regards,
Sachin
Check out my Blog
Anonymous
Not applicable

Hi @bhdben ,

I created a sample pbix file(see the attachment), please check if that is what you want.

1. Create a calculated column to judge if QA grade is unacceptable

UnacceptableFlag = IF('Table'[QA Grade]="Unacceptable",1,0)

2. Create a measure as below to get the culmulative values

CumulativeUnacceptable = 
VAR _date =
    SELECTEDVALUE ( 'Table'[Evaluation Date] )
VAR _property =
    SELECTEDVALUE ( 'Table'[Property] )
VAR _QAGrade =
    SELECTEDVALUE ( 'Table'[QA Grade] )
VAR _predate =
    CALCULATE (
        MAX ( 'Table'[Evaluation Date] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Property] = _property
                && 'Table'[Evaluation Date] < _date
        )
    )
VAR _preunac =
    CALCULATE (
        MAX ( 'Table'[Evaluation Date] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Property] = _property
                && 'Table'[Evaluation Date] < _date
                && 'Table'[QA Grade] = "Unacceptable"
        )
    )
RETURN
    IF (
        _preunac = _predate
            && _QAGrade = "Unacceptable",
        CALCULATE (
            SUM ( 'Table'[UnacceptableFlag] ),
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[Property] = _property
                    && 'Table'[Evaluation Date] <= _predate
            )
        ),
        MAX ( 'Table'[UnacceptableFlag] )
    )

vyiruanmsft_0-1729064352011.png

In addition, you can refer the following blog to get it:

Accumulative, conditional accumulative in Power Qu... - Microsoft Fabric Community

vyiruanmsft_1-1729064433166.png

Best Regards

SachinNandanwar
Super User
Super User

If there are 3 continous Unacceptable followed by anything but "Unacceptable"  should the measure display be like this ?
QA Grade              Measure

Unacceptable         0
Unacceptable         1
Unacceptable         2
Progress                 0

and how do you define the order of QA Grade ?



Regards,
Sachin
Check out my Blog

yes

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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