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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
InsureBI
Advocate II
Advocate II

Moving Average Formula ERROR

I have a table of policy coverage and effective date and I am trying to compute a daily moving average of premium.  Here is the formula I constructed, utilizing answers to similar questions on this forum.

 

SumCov = SUM (Policy[Coverage])

MovAvg = CALCULATE(AVERAGE(Policy[SumCov]),FILTER(ALL(Policy),Policy[EFF_DATE] <= EARLIER(Policy[EFF_DATE])))

 

The (simplified) Policy table with the computed measures SumCov and MovAvg should look like this:

Coverage, Eff_Date,SumCov,MovAvg

100, 6/1/2016,100,100

200,6/2/2016,900,300

600,6/2/2016,900,300

100,6/3/2016,1000,250

 

The formula for the new measure (MovAvg) results in the following error:

"Failed to resolve name 'SumCov'. It is not a valid table, variable, or function name."

 

It looks like I can't use a new measure inside a function.  If so, how should I go about computing the daily moving average.

 

Thank you.

 

5 REPLIES 5
Sean
Community Champion
Community Champion

@InsureBI Try these MEASURES

 

SumCov MEASURE =
CALCULATE (
    SUM ( Policy[Coverage] ),
    FILTER ( ALL ( Policy ), Policy[Eff_Date] <= MAX ( Policy[Eff_Date] ) )
)

MovAvg MEASURE =
DIVIDE (
    [SumCov],
    CALCULATE (
        COUNTROWS ( Policy ),
        FILTER ( ALL ( Policy ), Policy[Eff_Date] <= MAX ( Policy[Eff_Date] ) )
    ),
    0
)

@Sean thanks, this works with one change.  Replace MAX with EARLIER.

 

Your help is much appreciated.

Sean
Community Champion
Community Champion

@InsureBI I read your post to mean you want a MovAvg => MEASURE Smiley Happy So that's what I provided...

 

DAX - Moving Average.png

 

Apparently you want a Calculated COLUMN so go with @Vvelarde's formula

Vvelarde
Community Champion
Community Champion

 

MovAvg = CALCULATE(AVERAGE(Policy[Coverage]),FILTER(ALL(Policy),Policy[EFF_DATE] <= EARLIER(Policy[EFF_DATE])))




Lima - Peru

Thanks.

 

So you are suggesting that I drop the table reference to the calculated measure.  I did and got the same error message. 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.