Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hey All
I'm trying to calculate a measure (e.g. Avg Sales) for the period of previous 11 month from the current selected month, here is what I wrote :
Solved! Go to Solution.
I instructed you that you should create a column with consecutive numbering of fiscal months. I'm not talking about 1-12 but CONSECUTIVE numbers from 1 up to the last month you have in your calendar. Year has nothing to do with this.
I instructed you that you should create a column with consecutive numbering of fiscal months. I'm not talking about 1-12 but CONSECUTIVE numbers from 1 up to the last month you have in your calendar. Year has nothing to do with this.
// FiscalMonthID starts with 1 and goes up by 1
// until the very last fiscal month you have in
// the table.
AVGSales Snapshot =
var __minNumberOfMonths = 12
var __oneFullFiscalMonthVisible =
var __oneMonthVisible = HASONEVALUE( DimDate[FiscalMonthID]
var __dayCount = COUNTROWS( DimDate )
var __fullMonthDayCount =
CALCULATE(
COUNTROWS( DimDate ),
DimDate[FiscalMonthID] IN DISTINCT( DimDate[FiscalMonthID] ),
ALL( DimDate )
)
return
__oneMonthVisible
&&
( __dayCount = _fullMonthDayCount )
var __thereIsEnoughMonthsToCalcOver =
SELECTEDVALUE( DimDate[FiscalMonthID] ) >= __minNumberOfMonths
var __output =
if(
__oneFullFiscalMonthVisible
&&
__thereIsEnoughMonthsToCalcOver,
var __currentMonthID = SELECTEDVALUE( DimDate[FiscalMonthID] )
var __lowerBound = __currentMonthID - __minNumberOfMonths + 1
var __upperBound = __currentMonthID - 1
return
AVERAGEX(
CALCULATETABLE(
Distinct( DimDate[FiscalMonthID] ),
DimDate[FiscalMonthID] >= __lowerBound,
DimDate[FiscalMonthID <= __upperBound,
all( DimDate )
),
[Average Sales]
)
)
return
__output
Wow, Thanks for your help
would you please explain how it filters the year ?
If FiscalMonthID = 12 then the previous 12 month will be in the same year, but what if FiscalMonthID = 7 ?
I do have a Month Number Column ("FinMonthNumber") starting from 1 as the beginning of Fincancial Year.
The question is how to select multiple months. something like FinMonthNumber <= 6 will not work for Financial Months of 1 up to 6
Such a measure will be much simpler if you number your financial months consecutively starting with 1 (the very first month in your calendar). Why mess with years and months when you can use month numbers only? If you want to see how to correctly tackle financial calendars, you can go to Custom time-related calculations – DAX Patterns.
No one Knows how to make it work ?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
37 | |
25 | |
19 | |
14 | |
8 |
User | Count |
---|---|
69 | |
48 | |
44 | |
19 | |
15 |