问题
Need to calculate YTD Average and LYTD Average in DAX , Our Fiscal year starts from Apr. So if my current day is 5th of the June 2017 then lytd_AVG would be from Apr to June would be (MTD Aprn 17) + (MTD May 17) + (MTD June 17)/3
and LYTD_AVG would be (MTD Apr 16) + (MTD May 16) + (MTD June 16)/3
Assuming my current date is 06-03-2017, the YTD avg would be 60
回答1:
Assuming your data is given monthly (since you have no sample data), for YTD you should be able to use something that looks like this:
YTD Avg = CALCULATE(AVERAGE(Table[Value]), DATESYTD(Table[Date], "03-31"))
The last argument specifies the year-end date (Reference).
You can use the SAMEPERIOODLASTYEAR
function for LYTD:
LYTD Avg = CALCULATE(AVERAGE(Table[Value]),
SAMEPERIODLASTYEAR(DATESYTD(Table[Date], "03-31")))
Edit: Since your data is daily, we need to do a bit more work.
First, add month and year calculated columns to your table:
Month = MONTH(Table[Date])
FiscalYear = YEAR(MINX(DATESYTD(Table[Date], "03-31"), [Date]))
Then you will group by months in your measures:
YTD = AVERAGEX
SUMMARIZE(Table1,
Table1[Month],
"MTDAmount", SUM(Table1[Amount])),
[MTDAmount])
LYTD = AVERAGEX(
SUMMARIZE(
FILTER(ALL(Table1),
Table1[Month] IN VALUES(Table1[Month]) &&
Table1[FiscalYear] = MAX(Table1[FiscalYear]) - 1),
Table1[Month],
"MTDAmount", SUM(Table1[Amount])),
[MTDAmount])
You should then be able to build tables like this:
来源:https://stackoverflow.com/questions/49430400/ytd-average-in-dax