Skip to content

Allocation of a Monthly Product Budget using the TREATAS and FILTER functions

>> Download the sample (Power BI)

This sample allocates a monthly product budget down to individual days without using model relationships (with the Calendar Table), using instead one of two methods: the FILTER function or the TREATAS function.

Measures - Product, Budget, & Calendar Time

Section titled “Measures - Product, Budget, & Calendar Time”
Product Budget Allocation =
VAR DaysinContext =
COUNTROWS ( Calendar_Table ) //Finds how many dates in date context
VAR DaysinMonth =
CALCULATE (
COUNTROWS ( Calendar_Table ),
ALL ( Calendar_Table ),
VALUES ( Calendar_Table[Month & Year] )
) //Finds how many dates within each month
VAR CurrentMonth =
SELECTEDVALUE ( Calendar_Table[Month Name] )
VAR MonthlyBudgetAmount =
CALCULATE (
SUM ( 'Product Budget'[2019 Budget] ),
FILTER (
ALL ( 'Product Budget'[Month] ),
CurrentMonth = 'Product Budget'[Month]
)
) //Sums up the Total Budget for the Current Month
RETURN
IF (
OR (
HASONEVALUE ( Calendar_Table[Date] ),
HASONEVALUE ( Calendar_Table[Month & Year] )
),
DIVIDE ( DaysinContext, DaysinMonth, 0 ) * MonthlyBudgetAmount,
MonthlyBudgetAmount
)
//Retrieves Product Budget Allocations over any date context)
Product Budget Allocation 2 =
VAR DaysinContext =
COUNTROWS ( Calendar_Table ) //Finds how many dates in date context
VAR DaysinMonth =
CALCULATE (
COUNTROWS ( Calendar_Table ),
ALL ( Calendar_Table ),
VALUES ( Calendar_Table[Month & Year] )
) //Finds how many dates within each month
VAR MonthlyBudgetAmount =
CALCULATE (
SUM ( 'Product Budget'[2019 Budget] ),
TREATAS ( VALUES ( Calendar_Table[Month Name] ), 'Product Budget'[Month] )
) //Sums up the Total Budget for the Current Month
RETURN
IF (
OR (
HASONEVALUE ( Calendar_Table[Date] ),
HASONEVALUE ( Calendar_Table[Month & Year] )
),
DIVIDE ( DaysinContext, DaysinMonth, 0 ) * MonthlyBudgetAmount,
MonthlyBudgetAmount
)
//Retrieves Product Budget Allocations over any date context)
Total Sales =
SUMX ( Sales_Table, Sales_Table[Unit Price] * Sales_Table[Quantity] )
Calendar_Table =
GENERATE (
CALENDAR ( DATE ( 2017, 1, 1 ), DATE ( 2019, 12, 31 ) ),
VAR currentDay = [Date]
VAR Day =
DAY ( currentDay )
VAR Month =
MONTH ( currentDay )
VAR Year =
YEAR ( currentDay )
RETURN
ROW ( "Day", day, "Month", month, "Year", year )
)
Product Budget =
ADDCOLUMNS (
CROSSJOIN (
SUMMARIZECOLUMNS ( Sales_Table[Product] ),
DISTINCT ( Calendar_Table[Date].[Month] )
),
"2019 Budget",
CALCULATE ( [Total Sales], Calendar_Table[Year] = 2018 ) * 1.075
)