Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Jitmondo
Helper III
Helper III

DAX Help - Average Excluding zero and SAME PERIOD LASTYEAR

Hi,

 

stuggling to get the below formula to work and as it is shows blanks...

CALCULATE(AVERAGE(FIELD]),
 
FILTER(ALL(Dates),Dates[Year]=max(Dates[Year])-1), SAMEPERIODLASTYEAR(Dates[Date]),
 
FILTER(TABLE, FIELD] <> 0))
 
right now the visual this is for has a sameperiod last year average which works however includes zeros which I dont want.
I am trying to add the exclude zero part of the formula but keep getting blank?
 
any ideas on what I could do here?
 
thanks in advance
1 ACCEPTED SOLUTION
bcdobbs
Super User
Super User

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?


Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

2 REPLIES 2
bcdobbs
Super User
Super User

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?


Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

bcdobbs you are a rockstar ! thanks this worked exactly as you said. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.