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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Calculate last 7 days average using the last non-blank value

Hello,

I have a measure that calculates the last 7 days average starting from today and ranging back one week. The problem is that usually our data is about 2 weeks behind so I am looking for a way to modify the measure to find the last non blank value and then subtract the last 7 days. Please ignore last part, it just filters the type. THANKS!

7DayAvg =
CALCULATE(
    AVERAGE(LabResults[Result]),
    (FILTER(DimDates, DimDates[Date] < today()  &&  DimDates[Date] >= today() - 7)),
    CONTAINSSTRING(LabResults[Type], "Test A"))
1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

Please try this measure. I assume that for dates that don't have values, LabResults table will have blank in Result column. 

7DayAvg =
VAR _lastDate = MAXX ( FILTER ( LabResults, LabResults[Result] <> BLANK () ), LabResults[Date] )
RETURN
    CALCULATE (
        AVERAGE ( LabResults[Result] ),
        (
            FILTER (
                DimDates,
                DimDates[Date] <= _lastDate
                    && DimDates[Date] > _lastDate - 7
            )
        ),
        CONTAINSSTRING ( LabResults[Type], "Test A" )
    )

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @Anonymous 

 

Please try this measure. I assume that for dates that don't have values, LabResults table will have blank in Result column. 

7DayAvg =
VAR _lastDate = MAXX ( FILTER ( LabResults, LabResults[Result] <> BLANK () ), LabResults[Date] )
RETURN
    CALCULATE (
        AVERAGE ( LabResults[Result] ),
        (
            FILTER (
                DimDates,
                DimDates[Date] <= _lastDate
                    && DimDates[Date] > _lastDate - 7
            )
        ),
        CONTAINSSTRING ( LabResults[Type], "Test A" )
    )

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.