Forum Discussion

MrFahrenheit's avatar
MrFahrenheit
Helper I
4 years ago
Solved

Count Rows Based On Previous Row's value.

I have one column and it has 0s and 1s in it. I ONLY want to count the 0s which are followed by a 1 in the next row. For example, 0,1,0,1,0,1 would count 3 x 0s. Another example, 0,0,0,0,1 would only...
  • Fowmy's avatar
    4 years ago

    MrFahrenheit 

    First, add an index column to your table in Power Query:


    Then create the following measure to calculate the count:

    Zero Count = 
        SUMX(
            Table4,
            VAR __CURRENTINDEX = Table4[Index]
            VAR __NEXTINDEX = __CURRENTINDEX + 1
            VAR __CURRENTDIGIT = Table4[Digit]        
            VAR __NEXTDIGIST = CALCULATE( MAX(Table4[Digit]) , Table4[Index] = __NEXTINDEX , REMOVEFILTERS(Table4))
            RETURN
            INT(__CURRENTDIGIT=0 && __NEXTDIGIST = 1)
        )