Forum Discussion

seanpatten11's avatar
seanpatten11
Regular Visitor
8 years ago
Solved

How to retrieve previous row in the same table

Hi, I have the following table structure and would like to create a calculated column based on the previous months sales for that sales person and I constantly get "Multiple rows are returned", please see structure and formula below:

DateSalesPersonSalesFigure
01/01/2017Sales1100
01/01/2017Sales2100
01/01/2017Sales3100
01/02/2017Sales1200
01/02/2017Sales2200
01/02/2017Sales3200
01/03/2017Sales1300
01/03/2017Sales2300
01/03/2017Sales3300

 

 Formula:

PreviousMonthsValue = LOOKUPVALUE(Table[SalesFigure], Table[SalesPerson], VALUE(Table[SalesPerson]), Table[Date], DATEADD (Table[Date], -1,  MONTH))

Does anyone have any ideas i can try?

Many thanks

  • Anonymous's avatar
    Anonymous
    8 years ago

    Hi seanpatten11,

     

    You can try to use below formula to get the previous month data.

    PreviousMonthsValue = 
    LOOKUPVALUE(Table1[SalesFigure],[SalesPerson],[SalesPerson],[Date],DATE([Date].[Year],[Date].[MonthNo]-1,[Date].[Day]))+0

     

    Regards,

    Xiaoxin Sheng

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi seanpatten11,

     

    You can try to use below formula to get the previous month data.

    PreviousMonthsValue = 
    LOOKUPVALUE(Table1[SalesFigure],[SalesPerson],[SalesPerson],[Date],DATE([Date].[Year],[Date].[MonthNo]-1,[Date].[Day]))+0

     

    Regards,

    Xiaoxin Sheng

  • Hi,

     

    Try this calculated column formula

     

    =CALCULATE(MAX([SalesFigure]),FILTER(Table1,[Date]<EARLIER([Date])&&[SalesPerson]=EARLIER([SalesPerson])))

    Hope this helps.