Forum Discussion
Anonymous
5 years agoNot applicable
Filtering last day with data
Hi, I'm trying to build a measure that shows the data either from yesterday or the day before depending on the day of the week. Since there are no new data uploads on Sunday, I want to show the d...
Anonymous
5 years agoNot applicable
Anonymous
For such calculations (and for many, many more reasons) you should have a Date table in your model. Cramping everything into one table is a sure way to fail miserably without even knowing when and where. Please refer to this article to know what a good model suitable for PBI should look like.
Here's a solution for the times when your model is correct:
[Last Day With Data] =
// Your 'Dates' table has to have
// fields like ShortDayName (Mon, Tue,...),
// LongDayName (Monday, Tuesday),
// WeekDayNumber (Monday = 1, Tuesday = 2,...)
// and more... It should also be marked as a Date
// table in the model.
var CurrentDay =
SELECTEDVALUE( 'Dates'[Date] )
var IsMonday =
SELECTEDVALUE( 'Dates'[WeekDayNumber] ) = 1
var LastDayWithData = CurrentDay - 1 - int( IsMonday )
var Result =
CALCULATE(
[Your Base Measure],
'Dates'[Date] = LastDayWithData
)
RETURN
Result