Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

how to Reference previous row in same column

I have one column like this

 

City

A

A

B

C

C

 

and my requirement is if previous(city)=city then 0 else city and first one should be  0

 

So output

 

city     Column

A         0

A         0 

B         B

C         C

C         0

8 Replies

  • PattemManohar's avatar
    PattemManohar
    Community Champion

    Anonymous  Please add an Index column in "Power Query Editor" and then add a new column in Data Pane as below

     

    CheckPrev = 
    VAR _PrevRow = LOOKUPVALUE(Test242PrevRow[City],Test242PrevRow[Index],Test242PrevRow[Index]-1)
    RETURN IF(Test242PrevRow[City]=_PrevRow || Test242PrevRow[Index] = 1,"0",Test242PrevRow[City])

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Is it possible without adding column?

      • PattemManohar's avatar
        PattemManohar
        Community Champion

        Anonymous  Don't think it's possible without having any supporting field to lookup on to retrieve next or previous row logic. 

         

        It's a dynamic solution and it will work irrespective of number of rows in your table....

    • Anonymous's avatar
      Anonymous
      Not applicable

      and in real time scenario i don't know how many rows are there so please provide dynamic solution

  • Anonymous's avatar
    Anonymous
    Not applicable

     I have below SSRS logic

     IIF(Previous(Fields!name.Value) = Fields!name.Value,"",Fields!name.Value )

     

    I want to implement it in Power BI.

    Note: My source is Azure Analysis Services so I can not create index column

     

    e.g

    Name  output

    A       

    A        

    B            B

    C            C

    • Anonymous's avatar
      Anonymous
      Not applicable

      Output = IF(CALCULATE(COUNT(Table1[Source]),FILTER(Table1,Table1[Source]=EARLIER(Table1[Source])))>1,"",Table1[Source])

      • Anonymous's avatar
        Anonymous
        Not applicable

        I want measure not calculated column as my source is AAS. it won't allow creation of new calculated column