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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
vanrensburga
Regular Visitor

Count consecutive values across columns where a value > x

Good day

I am relatively new to PowerBI, and I have the following table with #High % (>=65%) calculated correctly.  I want to count the consecutive years across the columns where the % is >= 65%, and the output should be as per below (Column Name # Consecutive years%.  However, the output I get is shown in bold, which is incorrect.  For the # consecutive, I created a Consecutive Years Temp with the following dax (see below the table) and then another measure for #consecutive years%.  What am I doing wrong?

Yr 1Yr 2Yr 3Yr 4Yr 5# High % (5Yrs)# Consecutive years %
13436%40%721%4%17%21 2
2406%64%99%5%376%31 4
166%64%74%17%349%31 2
135%151%6%45%13%22 2
71%112%27%113%70%42

 

--1st Measure
ConsecutiveYearsTemp =
IF (
    'CPR'[YR1%] > 0.65
        || 'CPR'[YR2%] > 0.65
        || 'CPR'[YR3%] > 0.65
        || 'CPR'YR4%] > 0.65
        || 'CPR'[YR5%] > 0.65,
    1,
    0
)
--2nd Measure
ConsecutiveYears =
CALCULATE (
    MAXX (
        FILTER (
            ALL ( 'CPR' ),
            'CPR'[CurrentPeriodExpiryDate] <= 'CPR'[CurrentPeriodExpiryDate]
                && 'CPR'[YR1%] > 0.65
        ),
        'CPR'[ConsecutiveYearsTemp] + 1
    ),
    'CPR'[ConsecutiveYearsTemp] + 1
)


Cheers
 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@vanrensburga , This should be end

IF (
'CPR'[YR1%] > 0.65
&& 'CPR'[YR2%] > 0.65
&& 'CPR'[YR3%] > 0.65,
1,
0
)

Also, you can try measures like
if( CALCULATE(Countx(filter(Values('Date'[Year]), [%] >.65), [Year]) , WINDOW(-2,REL, 0, REL, ALLSELECTED('Date'[Year]),ORDERBY([Year],Desc))) >=3,1,0)

Continue to explore Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc
https://medium.com/@amitchandak/power-bi-window-function-3d98a5b0e07f


View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@vanrensburga , This should be end

IF (
'CPR'[YR1%] > 0.65
&& 'CPR'[YR2%] > 0.65
&& 'CPR'[YR3%] > 0.65,
1,
0
)

Also, you can try measures like
if( CALCULATE(Countx(filter(Values('Date'[Year]), [%] >.65), [Year]) , WINDOW(-2,REL, 0, REL, ALLSELECTED('Date'[Year]),ORDERBY([Year],Desc))) >=3,1,0)

Continue to explore Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc
https://medium.com/@amitchandak/power-bi-window-function-3d98a5b0e07f


Thank you very much.  

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.