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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply

Please help!

I have to calculate the previous day's values from my table, for which I have created a measure and it is working fine 

previousdates =
var _PrevDate =
calculate(
MAX(data[Created Date]),
ALLSELECTED(data[Created Date]),
KEEPFILTERS(data[Created Date] < SELECTEDVALUE(data[Created Date]))
)
var _Index = CALCULATE( [Current IndexValue],
FILTER(ALL(data[Created Date]),
data[Created Date] = _PrevDate)
)
return _Index

the issue I am facing is that I have 2 filters for year and month, which I need. and a date slicer that chooses the date for the selected month. However, when I choose the first date of the month, it should show me values for the previous month's last date, ignoring the year/month filters, but it doesnt do so and instead returns a blank column. else the measure is working well for any date in the month. also, the dates arent continuous (weekends + holiday dates arent there) ..

is there a way to solve this?

1 ACCEPTED SOLUTION

Try using REMOVEFILTERS to explicitly remove the filters on Year and Month

var _PrevDate =
calculate(
    MAX(data[Created Date]),
    data[Created Date] < SELECTEDVALUE(data[Created Date]),
    REMOVEFILTERS(<Year Column>),
    REMOVEFILTERS(<Month Column>)
)

You'll probably need the REMOVEFILTERS on the _Index calculation too.

 

Best practice here would still be to use a date table.  You could use LASTNONBLANKVALUE to go back to the previous date that exists in the data.

View solution in original post

9 REPLIES 9

Hi @PaulOlding 

Thanks for the solution. However, this is again giving me previous values for other dates & not for the last date of the previous month when I choose the first date of selected month. for example, if i select July 1, it should give me previous values for June 30th. However since I need a slicer for month, I am getting a blank for this criteria.

@DataAnalyst_99  Which columns are you using for the Year and Month slicers?

I havent created a date table if that is what you are asking since a lot of dates are missing in my data..so the year & month values are coming from my data itself

I did try @ValtteriN solution which has a calendar date part of the dax formula and so created a calendar table, but since there are a lot of missing date values, it essentially failed. Also, it didnt solve my query for the previous date value for the first date of selected month 

Try using REMOVEFILTERS to explicitly remove the filters on Year and Month

var _PrevDate =
calculate(
    MAX(data[Created Date]),
    data[Created Date] < SELECTEDVALUE(data[Created Date]),
    REMOVEFILTERS(<Year Column>),
    REMOVEFILTERS(<Month Column>)
)

You'll probably need the REMOVEFILTERS on the _Index calculation too.

 

Best practice here would still be to use a date table.  You could use LASTNONBLANKVALUE to go back to the previous date that exists in the data.

@PaulOlding - That worked! Thank you! 

 

Final Dax:

previousdates =

var _PrevDate =

calculate(

MAX(data[Created Date]),

data[Created Date] < SELECTEDVALUE(data[Created Date]),

REMOVEFILTERS(data[Created Date].[Year]),

REMOVEFILTERS(data[Created Date].[Month])

 

)

var _Index = CALCULATE( [Current IndexValue],

FILTER(ALL(data[Created Date]),

data[Created Date] = _PrevDate) ]),

REMOVEFILTERS(data[Created Date].[Year]),

REMOVEFILTERS(data[Created Date].[Month])

)

return _Index

ValtteriN
Super User
Super User

Hi,

Try something like this:

data:

ValtteriN_0-1658477749112.png


Dax:

Previousdate value =
var _pdate = CALCULATE(MAX(Cumulativetotal[Date]),ALL(Cumulativetotal[Date]),Cumulativetotal[Date]=MAX('Calendar'[Date])-1)
return

CALCULATE(SUM(Cumulativetotal[Value]),all(Cumulativetotal[Date]),Cumulativetotal[Date]=_pdate)

end result:

ValtteriN_1-1658477866174.png

Note that the value returned is 30.6.2022 from test data -> the function works

In general I would avoid using multiple date filters since they will often conduse end-users.

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi @ValtteriN,

Thank you for your solution. However it didnt work for me..

 

DataAnalyst_99_0-1658479614672.png

 

As you can see, for the first date of the month, I am getting no values for the previous date..
if I change the dates, I do get values..


DataAnalyst_99_1-1658479751299.png

 

Hi @DataAnalyst_99 

The behaviour suggests the year and month is in the filter context when _PrevDate is being calculated.  If you select the 1st of the month there is no previous date in the same month.

Perhaps a revised _PrevDate will work

var _PrevDate =
calculate(
    MAX(data[Created Date]),
    data[Created Date] < SELECTEDVALUE(data[Created Date])
)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.