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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
waldnerr
Helper I
Helper I

Rolling 12 month average not working if no values in month

Hi,

 

i have calculated the rolling 12 month average with subsequent DAX formulas for Amount and Hit Rate:

Amount (Euro, R12M) =
VAR NumOfMonth = 12
VAR LastCurrentDate =
    max('Date (Date Stage Set)'[Date])
VAR Period =
        DATESINPERIOD (
        'Date (Date Stage Set)'[Date],
        LastCurrentDate,
        - NumOfMonth,
        MONTH
    )
VAR Result =
    CALCULATE (
        AVERAGEX ( VALUES ('Date (Date Stage Set)'[YYYY/MM] ),[Amount (Euro, Measure)]),
        Period
    )
   
VAR FirstDateInPeriod =
    MINX ( Period, 'Date (Date Stage Set)'[Date] )
VAR LastDateWithSales =
    MAX ( Opportunity[Date Stage set] )
RETURN
    IF ( FirstDateInPeriod <= LastDateWithSales, Result )
 
Hitrate Amount (Euro, R12M) =
VAR NumOfMonth = 12
VAR LastCurrentDate =
    max('Date (Date Stage Set)'[Date])
VAR Period =
    DATESINPERIOD (
        'Date (Date Stage Set)'[Date],
        LastCurrentDate,
        - NumOfMonth,
        MONTH
    )
VAR Result =
    CALCULATE (
        AVERAGEX ( VALUES ('Date (Date Stage Set)'[YYYY/MM] ), [Hitrate Amount (Euro)]),
        Period
    )
VAR FirstDateInPeriod =
    MINX ( Period, 'Date (Date Stage Set)'[Date] )
VAR LastDateWithSales =
    MAX ( Opportunity[Date Stage set] )
RETURN
    IF ( FirstDateInPeriod <= LastDateWithSales, Result )
 
The result looks ok:
waldnerr_0-1700033949909.png

 

waldnerr_1-1700033984674.png

 

When i introduce the Stage as column legend, the amount is not calculated correct anymore - i assume, if there is not a value available for each Stage in a specific month:

 

waldnerr_3-1700034168410.png

 

 

waldnerr_4-1700034292985.png

 

I would apprechiate your can help me to adapt the formula accordingly to make it work.

Thank you,

Best regards,

Reinhard


 

 

 

1 REPLY 1
lbendlin
Super User
Super User

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors