# DATEDIFF in Variables Possible?

Hi Team,
So I’ve been rolling the marble around my head for a couple of days trying to figure out a way to use DATEDIFF in a variable so I don’t have to add more columns to one of my data tables. I’m not sure if it can be done this way so I’m reaching out to my peeps to see if you can help or know the answer.

Here’s what I’m trying to do:

1. Determine the number of days between TODAY() and Opportunities[Date]
2. Filter the response Opportunities that have a date difference GTE 30 and less than 1 Year from today
3. Filter this response by a Status
4. Color code background of items that meet this criteria

My initial attempt is the code below (requirements where slightly different than described above, because requirements seem to change regularly) but I was trying to modify this code to do the above. However, when I tried to add a VAR using DATEDIFF for opportunities[Date] it doesn’t work.

QA Days =
VAR TodaysDate = TODAY() // I feel like I shouldn’t need this and just use TODAY in VAR OneYr but it didn’t work properly
VAR OneYr = TodaysDate + 365
RETURN
CALCULATE([Total Opportunities],FILTER(opportunities, opportunities[Date] < TODAY() && opportunities[Opportunity Status] IN {0, 1} && opportunities[Other Date] <= OneYr))

## Here are some sample code Determine the number of days between any 2 dates

``````DateDifference =
var todayDate = TODAY()
var newOpportunityDateatRandom = Date(2020,10,15)
return
DATEDIFF(todayDate, newOpportunityDateatRandom, DAY)

dateDifference =
var todayDate = TODAY()
return
DATEDIFF(todayDate,SELECTEDVALUE(Dates[Date]), DAY)
``````

FilterDataBasedOnDifference =
var todayDate = TODAY()
return
if (DATEDIFF(todayDate,SELECTEDVALUE(Dates[Date]), DAY) >= 30
&& DATEDIFF(todayDate,SELECTEDVALUE(Dates[Date]), DAY) <=60, DATEDIFF(todayDate,SELECTEDVALUE(Dates[Date]), DAY), Blank())

if you can attach your pbix file, it will be easier to update but I am hoping the code above will function as a starting point

Sorry for the delayed response C9411010! Your solution works perfectly for what I was trying to achieve!!

Thank you very much!!
D