Forum Discussion

Subhash08's avatar
Subhash08
Regular Visitor
2 years ago
Solved

Previous row value fetching

Hi, i created a new column named

nuova colonna new, the condition --> if my new_item_no column current row is blank, I want to fetch the previous row value. please help me

attaching a screenshot for reference

 

  • Hi Subhash08 

    Getting the previous row number in Power BI is not as easy as in Excel, but there are multiple ways to achive this, and the following is one example.  You can achieve your required output by creating a separate calculated table referencing with staggering index and the value you want to bring in the next row, 

     

     

     

    Create a relationship between the index calculated table and the data table using the staggered previous row in the calculated table as the reference key.  

    Then create a measure, concatenateXing the column you want to stagger the rows. 

     

    The output like below will be produced.  

    I attach the pbix as an example.  I am sure that there are many other sophisticated ways to achive this, too. 

     

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi Subhash08 

     

    Thanks for the reply from DataNinja777 . Here I have another idea in mind, and I would like to share it for reference.

     

    I used a portion of your data and then ran the following test.

     

    Create several calculated columns as follow

    Column = 
    VAR _previous = 'Table'[Sequence]
    VAR _maxs = CALCULATE(MAX([Sequence]), FILTER('Table', [New Item No_] <> BLANK() && _previous > [Sequence]))
    RETURN
    _maxs

     

    nuova colonna new = IF([New Item No_] <> BLANK(), [New Item No_], LOOKUPVALUE('Table'[New Item No_], 'Table'[Sequence], 'Table'[Column]))

     

    Result:

     

    Best Regards,
    Yulia Xu

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • Hi Subhash08 

    Getting the previous row number in Power BI is not as easy as in Excel, but there are multiple ways to achive this, and the following is one example.  You can achieve your required output by creating a separate calculated table referencing with staggering index and the value you want to bring in the next row, 

     

     

     

    Create a relationship between the index calculated table and the data table using the staggered previous row in the calculated table as the reference key.  

    Then create a measure, concatenateXing the column you want to stagger the rows. 

     

    The output like below will be produced.  

    I attach the pbix as an example.  I am sure that there are many other sophisticated ways to achive this, too. 

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Subhash08 

     

    Thanks for the reply from DataNinja777 . Here I have another idea in mind, and I would like to share it for reference.

     

    I used a portion of your data and then ran the following test.

     

    Create several calculated columns as follow

    Column = 
    VAR _previous = 'Table'[Sequence]
    VAR _maxs = CALCULATE(MAX([Sequence]), FILTER('Table', [New Item No_] <> BLANK() && _previous > [Sequence]))
    RETURN
    _maxs

     

    nuova colonna new = IF([New Item No_] <> BLANK(), [New Item No_], LOOKUPVALUE('Table'[New Item No_], 'Table'[Sequence], 'Table'[Column]))

     

    Result:

     

    Best Regards,
    Yulia Xu

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.