Forum Discussion
Calculate Ave Values in same Column by Date
Hi Experts,
Looking for help with a measure to calculate the difference in Column Values by Date,
I have created a Measure that gives me the average of the sum of a total clolumn by date ..
This is the measure >
9 Replies
- kentyler
Solution Sage
AVERAGEX(
Filter ( ALLSELECTED( 'Week/Week Data'[Report Date]),
'Week/Week Data'[Report Date] <= Max('Week/Week Data'[Report Date]) ),
[Total 61>180] )
to solve your problem you have to change this date in your FILTER to be either one week ahead of the date in the current row, or one week behind it.
setup 2 VAR statements before you call AVERAGEX
VAR Prev_Week = DATEADD('Week/Week Data'[Report Date],-7,DAY)and
VAR Next_Week = DATEADD('Week/Week Data'[Report Date],+7,DAY)then 2 VAR statements to store the result of calling AVERAGEX with the 2 dates
that will give you 2 VARs you can use to calculate the difference.
- RandyR1963Frequent Visitor
kentyler , Thank you for assisting, I think i am getting a little lost in your discription,
This is how i have interpreted how you have discribed,
My Original Measure was
AVERAGEX(
Filter ( ALLSELECTED( 'Week/Week Data'[Report Date]),
'Week/Week Data'[Report Date] <= Max('Week/Week Data'[Report Date]) ),
[Total 61>180] ) I Created a Copy of the Original Data set so i didn't mess it up, some value names changed.With the 2 VARs below, i am assuming to replace the BOLD section in original measure with either Next_Week or Prev_Week as in the New measures below
"setup 2 VAR statements before you call AVERAGEX"
VAR Prev_Week = DATEADD('Week/Week Data'[Report Date],-7,DAY)My Measure >
PrevWeek = VAR Prev_Week = DATEADD('Week/Week Data (2)'[Report Date], -7, DAY)RETURNAVERAGEX(Filter ( ALLSELECTED( 'Week/Week Data (2)'[Report Date]),Prev_Week <= Max('Week/Week Data (2)'[Report Date]) ),[SumTotal61>180]) This returns ERROR, Calc error in measure, [Next_Week}: A table of multiple Values was supplied where a single value was expectedand
VAR Next_Week = DATEADD('Week/Week Data'[Report Date],+7,DAY)My Measure >
NextWeek = VAR Next_Week = DATEADD('Week/Week Data (2)'[Report Date], +7, DAY)RETURNAVERAGEX(Filter ( ALLSELECTED( 'Week/Week Data (2)'[Report Date]),Next_Week <= Max('Week/Week Data (2)'[Report Date]) ),[SumTotal61>180]) This returns no results.. Same Error as above.Then you stated "then 2 VAR statements to store the result of calling AVERAGEX with the 2 dates"Which is my assumption these Measuers would be something like,NextWeek = Sum(Next_Week)andPrev_Week = Sum(Prev_Week),Then being able to do a measure called Variance = NextWeek-PrevWeek to get teh variance i am looking for .Now, the dates in my table is of a report that i have duplicated and Grouped the totals by the Report Date, could this be some of or all of the issue with the Error message? ,Thank you in advance for any guidence.Randy- kentyler
Solution Sage
My Measure >
PrevWeek = VAR Prev_Week = DATEADD('Week/Week Data (2)'[Report Date], -7, DAY)RETURNAVERAGEX(Filter ( ALLSELECTED( 'Week/Week Data (2)'[Report Date]),Prev_Week <= Max('Week/Week Data (2)'[Report Date]) ),[SumTotal61>180]) This returns ERROR, Calc error in measure, [Next_Week}: A table of multiple Values was supplied where a single value was expectedAdd another varVAR current_week = MAX( 'Week/Week Data (2)'[Report Date])
then temporarily have the measure return that VAR... see if it returns what you think it should
you can do the same thing in the measure that is trying to return the next week.
- amitchandak
Super User
RandyR1963 , For WOW, please refer by blog, How to use Rank to get last week's value.