Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MikeO
Helper I
Helper I

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!

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
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
    )
)

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yulgu-msft
Employee
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
    )
)

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you, Yuliana.

 

That formula worked perfectly.

MikeO
Helper I
Helper I

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.

 

Power BI Source Question.PNG

 

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!

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
Not applicable

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

Sorry for the confusion, Newspaper was an earlier name I had for the advertising source ("Source").  Newspaper should be replaced with Source wherever it appears.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.