Forum Discussion
NickPowerBI
6 years agoRegular Visitor
Latest Budget Version based on date filtering
We are looking for the latest budget based on a budget version and date filtering. Consider the following dataset: Budget Table (related to a date dimension) Project Name Subtask Budge...
Anonymous
6 years agoNot applicable
// For the below to work you have to:
// 1. Have a Dates table that's on the day granularity.
// 2. It must be the Date table in the model.
// 2. This table must be connected to the Budget Table.
// 3. Even though the granularity of the [Budget Table]
// is different than Dates, it must join on [Date]
// and granularity must be managed through the code,
// so you have to decide when to display the below.
// The below is additive across proj/subtask but is
// not additive over time. It only shows you the budget
// for any particular date and any subset of proj/tasks.
// If you want to make it somehow additive across time,
// you'll have to either modify the measure or create
// another one on top of this one.
[Budget] =
var __oneVersionVisible =
HASONEFILTER( 'Budget Table'[Budget Version] )
var __latestDate = LASTDATE( Calendar[Date] )
var __result =
if( __oneVersionVisible,
var __latestDates =
ADDCOLUMNS(
// Get all visible proj's and tasks
SUMMARIZE(
'Budget Table',
'Budget Table'[Project Name],
'Budget Table'[Subtask]
),
// For each of the proj/tasks find
// the last date before or on
// the current one that does have
// a value in the Budget Table.
"@LatestDate",
MAXX(
FILTER(
ALL( Dates ),
Dates[Date] <= __latestDate
&&
NOT( ISEMPTY(
CALCULATETABLE(
[Budget]
)
))
),
Dates[Date]
)
)
var __output =
CALCULATE(
SUM( 'Budget Table'[Budget] ),
TREATAS(
__latestDates,
'Budget Table'[Project Name],
'Budget Table'[Subtask],
'Dates'[Date]
)
)
return
__output
)
RETURN
__result