Forum Discussion
DAX Help - Average Excluding zero and SAME PERIOD LASTYEAR
- 4 years ago
Would be easier to diagnose with a demo pbix file (remove sensitive data).
I think however you're hitting an issue because in FILTER(TABLE, [FIELD] <> 0) you're putting the whole table into the filter context, which has the originally selected dates and then another filter with last years dates.
Try:CALCULATE( AVERAGE( TableName[FIELD] ), SAMEPERIODLASTYEAR( Dates[Date] ), TableName[FIELD] <> 0 )
If you specifically need the:
FILTER(ALL(Dates),Dates[Year]=max(Dates[Year])-1), SAMEPERIODLASTYEAR(Dates[Date]) that can go back in safely however I think the above should work in most situations where a year exists in the filter context already.
Other thoughts:- Make sure your date table has full years.
- Make sure your date table is marked as a date table.
- Does your fact table have data for the previous period in question?
Would be easier to diagnose with a demo pbix file (remove sensitive data).
I think however you're hitting an issue because in FILTER(TABLE, [FIELD] <> 0) you're putting the whole table into the filter context, which has the originally selected dates and then another filter with last years dates.
Try:
CALCULATE(
AVERAGE( TableName[FIELD] ),
SAMEPERIODLASTYEAR( Dates[Date] ),
TableName[FIELD] <> 0
)
If you specifically need the:
FILTER(ALL(Dates),Dates[Year]=max(Dates[Year])-1), SAMEPERIODLASTYEAR(Dates[Date]) that can go back in safely however I think the above should work in most situations where a year exists in the filter context already.
Other thoughts:
- Make sure your date table has full years.
- Make sure your date table is marked as a date table.
- Does your fact table have data for the previous period in question?
bcdobbs you are a rockstar ! thanks this worked exactly as you said.