cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
vega
Resolver III
Resolver III

Day to Day Calculated Column

Hello,

 

I have the following example dataset:

 

HotelDateAmount
A1/1/2017100
A1/2/2017200
A1/3/2017300
B1/1/2017400
B1/2/2017500
B1/3/2017600
A1/1/2018700
A1/2/2018800
A1/3/2018900
B1/1/20181000
B1/2/20181100
B1/3/20181200



What I'd like is a calculated column that computes the previous years amounts on a day to day level. So, instead of matching the 1/1/2018 to 1/1/2017, we are matching day of the week. So, we want to match 1/1/2018 to 1/2/2017, basically we want to subtract 364 days. So this is what I'm looking for;

HotelDateAmountDoD
A1/1/2017100 
A1/2/2017200 
A1/3/2017300 
B1/1/2017400 
B1/2/2017500 
B1/3/2017600 
A1/1/2018700200
A1/2/2018800300
A1/3/2018900 
B1/1/20181000500
B1/2/20181100600
B1/3/20181200 


 
Does anyone know how to go about doing this?

Thanks!

1 ACCEPTED SOLUTION
ccakjcrx
Resolver I
Resolver I

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! 

View solution in original post

2 REPLIES 2
ccakjcrx
Resolver I
Resolver I

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! 

Thank you, I appreciate it. I was also able to come up with an alternate solution. I'll leave it here in case it helps anyone else out in the future.

=
VAR previousDate = 'Legacy Trans'[Date]-364
RETURN
CALCULATE(
	SUM('Legacy Trans'[Amount]),
	ALLEXCEPT('Legacy Trans','Legacy Trans'[Hotel]),
	'Legacy Trans'[Dates] = previousDate
)

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors