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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Miinch87
Frequent Visitor

Measure for Moving Average / Simple Moving Average Problem

Hello,

i created a measure and i dont know why it shows the wrong result. The measure should calculate the moving average:

the exptected result is 161 and but it shows 1932. Maybe its a data format issue?

 

Miinch87_1-1670576758298.jpeg

 

Gleitender Durchschnitt = 

VAR NumOfMonths = 12

VAR LastCurrentDate =

   EOMONTH(TODAY(),-1)

VAR Period =

    DATESINPERIOD ( Datum[Date] , LastCurrentDate, - NumOfMonths, MONTH )

VAR Result =

    CALCULATE (

        AVERAGEX (

            VALUES ( Datum[Monat] ),

            Verkaufstransaktionen[Fakt. Menge]

        ),

        Period

    )

VAR FirstDateInPeriod = MINX ( Period, Datum[Date]  )

VAR LastDateWithSales = MAX ( Verkaufstransaktionen[Buchungsdatum] )

RETURN

    IF ( FirstDateInPeriod <= LastDateWithSales, Result )

 

thanks in advance and your help

 

Greetings

1 ACCEPTED SOLUTION
Miinch87
Frequent Visitor

Good Morning,
sorry for the delayed answer.

 

i found out that the measure doenst consider the empty values -> "ledger entry months" ... on the other side if there are some postings in the previous months it works just fine. 

 

If there are no posting in the previous 12 months than it shows the complete value = 1932 instead of 161 

 

i changed the measure to: 

 

i hope it fixes the Problem ... atleast it looks right

 

Greetings

Gleitender Durchschnitt = 

VAR NumOfMonths = 12

VAR LastCurrentDate =

   EOMONTH(TODAY(),-1)

VAR Period =

    DATESINPERIOD ( Datum[Date] , LastCurrentDate, - NumOfMonths, MONTH )

VAR Result =

    CALCULATE (

        DIVIDE(

            Verkaufstransaktionen[Fakt. Menge],

            12

        ),

        Period

    )

VAR FirstDateInPeriod = MINX ( Period, Datum[Date]  )

VAR LastDateWithSales = MAX ( Verkaufstransaktionen[Buchungsdatum] )

RETURN

    IF ( FirstDateInPeriod <= LastDateWithSales, Result )
 

View solution in original post

2 REPLIES 2
Miinch87
Frequent Visitor

Good Morning,
sorry for the delayed answer.

 

i found out that the measure doenst consider the empty values -> "ledger entry months" ... on the other side if there are some postings in the previous months it works just fine. 

 

If there are no posting in the previous 12 months than it shows the complete value = 1932 instead of 161 

 

i changed the measure to: 

 

i hope it fixes the Problem ... atleast it looks right

 

Greetings

Gleitender Durchschnitt = 

VAR NumOfMonths = 12

VAR LastCurrentDate =

   EOMONTH(TODAY(),-1)

VAR Period =

    DATESINPERIOD ( Datum[Date] , LastCurrentDate, - NumOfMonths, MONTH )

VAR Result =

    CALCULATE (

        DIVIDE(

            Verkaufstransaktionen[Fakt. Menge],

            12

        ),

        Period

    )

VAR FirstDateInPeriod = MINX ( Period, Datum[Date]  )

VAR LastDateWithSales = MAX ( Verkaufstransaktionen[Buchungsdatum] )

RETURN

    IF ( FirstDateInPeriod <= LastDateWithSales, Result )
 
FreemanZ
Community Champion
Community Champion

the measure seems fine. could you also provide some sample data?

Helpful resources

Announcements
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.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.