Forum Discussion

Taranggupta's avatar
Taranggupta
New Member
8 years ago
Solved

How to get previous row value for text column.

Hi,

 

I would like to get the previous row value for a text column using DAX.

 

Example: Text_column

                    A

                    B

                    C

 

Expected Output: 

             Text_column, Previous_value

                    A                    NULL

                    B                       A

                    C                       B

 

Please let me know incase of any clarification.

 

Thanks in Advance.

  • Taranggupta

     

    In DAX, there's no order internally for records in table. You have to add an index column in your table. 

     

     

    PreviousText = CALCULATE(MAX(Table1[Text]),FILTER(Table1,Table1[Index]=EARLIER(Table1[Index])-1))

     

    Regards,

     

     

3 Replies

  • v-sihou-msft's avatar
    v-sihou-msft
    Icon for Microsoft Employee rankMicrosoft Employee

    Taranggupta

     

    In DAX, there's no order internally for records in table. You have to add an index column in your table. 

     

     

    PreviousText = CALCULATE(MAX(Table1[Text]),FILTER(Table1,Table1[Index]=EARLIER(Table1[Index])-1))

     

    Regards,

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, 

       

      v-sihou-msft I am trying to replicate this and have added the index column, but getting a row context error from the EARLIER function onwards:

       

      previous index = CALCULATE(MAX('Curso Académico'[Curso]);FILTER('Curso Académico';'Curso Académico'[Index]=EARLIER('Curso Académico'[Index]))


       

      Any ideas what I'm doing wrong?

       

      Thanks!

       

      • dartmana's avatar
        dartmana
        Regular Visitor

        ...

        is the -1 missing at the end? 

         

        previous index = CALCULATE(MAX('Curso Académico'[Curso]);FILTER('Curso Académico';'Curso Académico'[Index]=EARLIER('Curso Académico'[Index])-1))