Forum Discussion
Find Average Using Most Recent Date
- 1 year ago
hi AntrikshSharma ,
yes, indeed. thank you very much for pointing this out.
try like this instead:
measure =VAR _table =ADDCOLUMNS(SUMMARIZE(CALCULATETABLE(fResults,dMembers[Expiry]>TODAY()),dMembers[MemberID],dMembers[Expiry]),"RecentDate",CALCULATE(MAX(fResults[ResultDate])))VAR _result =CALCULATE(AVERAGE(fResults[NewRating]),TREATAS(_table,dMembers[MemberID],dMembers[Expiry],fResults[ResultDate]))RETURN _result
hi LurkingDude ,
try like:
measure =
VAR _table =
ADDCOLUMNS(
SUMMARIZE(
fResults,
dMembers[MemberID],
dMembers[Expiry]
),
"RecentDate",
CALCULATE(MAX(fResults[ResultDate]))
)
VAR _result =
CALCULATE(
AVERAGE(fResults[NewRating]),
TREATAS(
CALCULATETABLE(
_table,
dMembers[Expiry]>TODAY()
),
dMembers[MemberID],
dMembers[Expiry],
fResults[ResultDate]
)
)
RETURN _result
- LurkingDude1 year agoFrequent Visitor
Whoa! No wonder I couldn't figure it out. LOL.
Thanks for the response. I will try this out at first opportunity.
So I understand what the code is doing, will the code line CALCULATE(MAX(fResults[ResultDate])) iterate over _table and return the max date for EACH MemberID? I don't see where the grouping by MemberID is happening. Is it in the Summarize function? (I'm not too familiar with that one.)
Thanks for helping me understand.- FreemanZ1 year agoSuper User
hi LurkingDude ,
yes, done with SUMMARIZE.
the code is not verified, please come back and @me, in case of issue.
- AntrikshSharma1 year agoCommunity Champion
- FreemanZ1 year agoSuper User
hi AntrikshSharma ,
yes, indeed. thank you very much for pointing this out.
try like this instead:
measure =VAR _table =ADDCOLUMNS(SUMMARIZE(CALCULATETABLE(fResults,dMembers[Expiry]>TODAY()),dMembers[MemberID],dMembers[Expiry]),"RecentDate",CALCULATE(MAX(fResults[ResultDate])))VAR _result =CALCULATE(AVERAGE(fResults[NewRating]),TREATAS(_table,dMembers[MemberID],dMembers[Expiry],fResults[ResultDate]))RETURN _result