Forum Discussion

MikeO's avatar
MikeO
Icon for Helper I rankHelper I
8 years ago
Solved

How can I build a relative comparison between rows?

I am tracking our advertisements by start and end date but to determine end date I need to determine start date of the next time an advertisement runs in same the advertising source.

 

I have already built a ranking column called "run number" where the latest run date is numbered 1 and the oldest run date is the highest value.

 

I have tried the following formula and while I get an end date whenever the run number is 1, I just get a blank for the rest of the run numbers:

 

End Date = IF(Table1[Run Number]=1,TODAY(),CALCULATE(MAX(Table1[Adjusted Run Date]),FILTER(Table1,Table1[Run Number]=Table1[Run Number]-1&&Table1[Newspaper]=EARLIER(Table1[Newspaper]))))

 

I have provided a table below (I have inserted what I want to appear in the end date column:)

 

SourceCreative NameAdjusted Run DateRun NumberEnd Date
AH12/31/201642/10/2017
AL2/10/201733/24/2017
AH3/24/201724/7/2017
AH4/7/201715/12/2018
BL2/12/201773/7/2017
BH3/7/201763/12/2017
BW3/12/201753/19/2017
BL3/19/201744/4/2017
BK4/4/201734/18/2017
BW4/18/201725/4/2017
BK5/4/201715/12/2018
CY2/13/201752/20/2017
CW2/20/201743/16/2017
CL3/16/201733/17/2017
CH3/17/201723/20/2017
CW3/20/201715/12/2018
DH1/22/201882/13/2018
DT2/13/201872/22/2018
DT2/22/201862/26/2018
DH2/26/201852/26/2018
DT2/26/201842/27/2018
DT2/27/201833/5/2018
DH3/5/201823/5/2018
DW3/5/201815/12/2018

 

I have even tried using the following LOOKUPVALUE formula and receive an error message saying "The number of arguments is invalid.  Function LOOKUPVALUE must have a value for each specified column reference."

 

End Date = IF('NP Orders'[Run Number]=1,TODAY(),LOOKUPVALUE('NP Orders'[Adjusted Run Date],'NP Orders'[Run Number],'NP Orders'[Run Number]-1,'NP Orders'[Newspaper]=MAX('NP Orders'[Newspaper])))

 

Any help would be much appreciated!

  • Hi MikeO,

     

    Please refer to below formula:

    End Date =
    IF (
        'Table1'[Run Number] = 1,
        TODAY (),
        LOOKUPVALUE (
            'Table1'[Adjusted Run Date],
            'Table1'[Source], 'Table1'[Source],
            'Table1'[Run Number], 'Table1'[Run Number] - 1
        )
    )

     

    Best regards,

    Yuliana Gu

6 Replies

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

    Hi MikeO,

     

    Please refer to below formula:

    End Date =
    IF (
        'Table1'[Run Number] = 1,
        TODAY (),
        LOOKUPVALUE (
            'Table1'[Adjusted Run Date],
            'Table1'[Source], 'Table1'[Source],
            'Table1'[Run Number], 'Table1'[Run Number] - 1
        )
    )

     

    Best regards,

    Yuliana Gu

    • MikeO's avatar
      MikeO
      Icon for Helper I rankHelper I

      Thank you, Yuliana.

       

      That formula worked perfectly.

  • I am tracking our advertisements by start and end date but to determine end date I need to determine start date of the next time an advertisement runs in same the advertising source.

    I have already built a ranking column called "run number" where the latest run date is numbered 1 and the oldest run date is the highest value.

    I have tried the following formula and while I get an end date whenever the run number is 1, I just get a blank for the rest of the run numbers:

     

    End Date = IF(Table1[Run Number]=1,TODAY(),CALCULATE(MAX(Table1[Adjusted Run Date]),FILTER(Table1,Table1[Run Number]=Table1[Run Number]-1&&Table1[Newspaper]=EARLIER(Table1[Newspaper]))))

    I have provided a table below (I have inserted what I want to appear in the end date column.

     

     

    I have even tried using the following LOOKUPVALUE formula and receive an error message saying "The number of arguments is invalid. Function LOOKUPVALUE must have a value for each specified column reference."

    End Date = IF('NP Orders'[Run Number]=1,TODAY(),LOOKUPVALUE('NP Orders'[Adjusted Run Date],'NP Orders'[Run Number],'NP Orders'[Run Number]-1,'NP Orders'[Newspaper]=MAX('NP Orders'[Newspaper])))

    Any help would be much appreciated!

    • MikeO's avatar
      MikeO
      Icon for Helper I rankHelper I

      It looks like this post was first flagged as spam, which has since been corrected although it also appears to have made it miss the attention of everyone.  If anyone can help with this question that would be much appreciated!

      • Anonymous's avatar
        Anonymous
        Not applicable

        There is something missing in your simple data. What is the data in [Newspaper]?