Forum Discussion

vega's avatar
vega
Resolver III
8 years ago
Solved

Day to Day Calculated Column

Hello,   I have the following example dataset:   Hotel Date Amount A 1/1/2017 100 A 1/2/2017 200 A 1/3/2017 300 B 1/1/2017 400 B 1/2/2017 500 B 1/3/2017 600 ...
  • ccakjcrx's avatar
    8 years ago

    Hey vega!

     

    I was able to use LOOKUP and specify both 364 days ago, and hotel. I added a calculated column to my test data model using the following expression:

     

    PriorYearHotelValue = 
    IF(
        Sheet1[Hotel] = "A",
        LOOKUPVALUE(Sheet1[Value],Sheet1[Date],Sheet1[Date] - 364,Sheet1[Hotel], "A"),
        LOOKUPVALUE(Sheet1[Value],Sheet1[Date],Sheet1[Date] - 364,Sheet1[Hotel], "B")
    )

     

    In my test data, I started with three columns: Date, Hotel, & Value. The LOOKUP expression looks for the value in Sheet1[Value], where date matches 364 days ago, and hotel matches A. I only have two hotels, so my IF statement executes the first LOOKUP if matches on A, and the second if not.

     

    Click HERE to access my .pbix file if you need it.

     

    Hope this helps!