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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

Create a measure to calculate the previous date from another Date column in the same table.

 

 

Hi All,

I am stuck with a requirement which appears to be deceptively simple. I have the following table:

sau001_0-1639002832505.png

 

For every row, I want to calculate the previous date. Example in the New column below.

sau001_1-1639002943293.png

 

I tried with DATEADD. But, this expects a table of Dates.

 

Link to Excel is here.

Link to Power BI with this Excel is here

Any suggestions?

 

Please, I am working on an online model, hence, I cannot created calculated columns or additional tables.

 

Thanks,

Sau

 

 

1 ACCEPTED SOLUTION
ebeery
Memorable Member
Memorable Member

@Anonymous how about something like this?

Previous Day Measure = 
Var _SelectedDay = SELECTEDVALUE('Table'[date])
Var _PreviousDay = _SelectedDay - 1
VAR _Result =
IF(
    HASONEVALUE('Table'[date]), _PreviousDay
)
Return
_Result

 

ebeery_0-1639004313410.png

 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

 

The following measure appears to work

PreviousDate = 
var tbl=DATEADD(Sales[date],-1, DAY)
return FIRSTDATE(tbl)
 
 
ebeery
Memorable Member
Memorable Member

@Anonymous how about something like this?

Previous Day Measure = 
Var _SelectedDay = SELECTEDVALUE('Table'[date])
Var _PreviousDay = _SelectedDay - 1
VAR _Result =
IF(
    HASONEVALUE('Table'[date]), _PreviousDay
)
Return
_Result

 

ebeery_0-1639004313410.png

 

Anonymous
Not applicable

Thanks for replying @ebeery 

Before I accept your solution, I have just one question.

 

The syntax that you have used for calculating the previous date - is this the standard way to compute date additions. i.e. if I were to add 365, would it give me next year?

Var _PreviousDay = _SelectedDay - 1

 

@Anonymous to be honest, I'm not enough of a DAX expert to answer that definitively.  It seems to work well in my testing but possibly there are edge cases out there on which it would fail.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors