Forum Discussion

NQT1711's avatar
NQT1711
Frequent Visitor
2 years ago
Solved

How to get previous values

Hi there, 

 

I have a table like that:

Market_WeekSum Quantity
2705
38272
48285
68705
78717
88726
109211
1240157
1343308
1547564
1649146

And i want to get previous values like:

Market_WeekSum QuantityPrevious Sum Quantity
2705 
38272705
482858272
687058285
787178705
887268717
1092118726
12401579211
134330840157
154756443308
164914647564

How can I handle this?

Thank you and I look forward to your support.

  • Hi NQT1711 

    I am sure there are many ways to do this, but one way is to create a calculated column for the indexing by rankx, and then to create another calculated column bringing the previous row.  

     

     

    Best regards,

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi NQT1711 ,

     

    Creating calculated columns is indeed a good option, as DataNinja777  provides.


    However, if your data model is too large, it may increase the memory burden since the calculated columns will actually be added to the data model.

    Perhaps create a measure is a good option, refer to the following formula:

    MEASURE =
    MAXX (
        FILTER ( ALL ( 'Table' ), 'Table'[Market_Week] < MAX ( 'Table'[Market_Week] ) ),
        [Sum Quantity]
    )
    

     

    Best Regards,
    Adamk Kong

     

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

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi NQT1711 ,

     

    Creating calculated columns is indeed a good option, as DataNinja777  provides.


    However, if your data model is too large, it may increase the memory burden since the calculated columns will actually be added to the data model.

    Perhaps create a measure is a good option, refer to the following formula:

    MEASURE =
    MAXX (
        FILTER ( ALL ( 'Table' ), 'Table'[Market_Week] < MAX ( 'Table'[Market_Week] ) ),
        [Sum Quantity]
    )
    

     

    Best Regards,
    Adamk Kong

     

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

  • There's two way that you can do it now. 

    1. Create a Measure

    var _selecteddate= FIRSTDATE('Calendar'[week])-1

    var PreviousDayTotal=CALCULATE(SUM(QUANTITTY),TREATAS({_selecteddate},'Calendar'[week]))

    RETURN

    IF(SUM(QUANTITTY)=BLANK(),BLANK(), SUM(QUANTITTY))

     

    2. New features

    You can calculate the previous value using new calculation as well which is the prefered solution now.

    Visual calculations (preview) | Microsoft Power BI Blog | Microsoft Power BI

    • Wilson_'s avatar
      Wilson_
      Memorable Member

      Kaviraj11,

       

      I strongly disagree that visual calculations are the preferred solution.

       

      They're still a preview feature. They are also specific to the visual only and cannot be reused anywhere else.

  • Hi NQT1711 

    I am sure there are many ways to do this, but one way is to create a calculated column for the indexing by rankx, and then to create another calculated column bringing the previous row.  

     

     

    Best regards,