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
RajK2
Frequent Visitor

Average for each 4 Quarter - Moving Average DAX

Dear Team,

 

I would like to calculate moving average as my DAX Formuls didn't works well.

 

My fact table doesn't have value on specific date/month  then my 4 Quarter average doesn't calculate as expected.

 

Example measurement takes where we don't have value in Fact Table then it takes SUM of Total / 4 as average (wrong answer) = 34,637

 

How can we fix this. pls suggest

 

VAR __LAST_DATE = ENDOFQUARTER('Calendar'[EO_Month])
VAR __PERIOD = DATESBETWEEN(
            'Calendar'[EO_Month],
            STARTOFQUARTER(DATEADD(__LAST_DATE, -3, QUARTER)),
            ENDOFQUARTER(DATEADD(__LAST_DATE, 0, QUARTER))
        )
RETURN
    CALCULATE(AVERAGEX(
    VALUES('Fact'[Date]),
    IF([Values]=BLANK(),0,[Values])
),__PERIOD)

 

Capture1.PNG

2 REPLIES 2
v-heq-msft
Community Support
Community Support

Hi @RajK2 ,
Here some steps that I want to share, you can check them if they suitable for your requirement.
Here is my test data:

vheqmsft_0-1715750205933.png

Create two columns

YearQtr = CONCATENATE(LEFT([Year-Qtr],2),RIGHT([Year-Qtr],1))
Rank = RANKX('Table',[YearQtr],,ASC)

vheqmsft_1-1715750261371.png

Create measure

Average 4 quarter = 
VAR _sum = 
CALCULATE(
    SUM('Table'[AOP$]),
    FILTER(
        ALL('Table'),
        'Table'[Rank] >= SELECTEDVALUE('Table'[Rank]) - 3 && 'Table'[Rank] <= SELECTEDVALUE('Table'[Rank])
    )
)
RETURN
IF(
    _sum = BLANK(),
    0,
    _sum/4
)

Final output

vheqmsft_2-1715750298289.png

Best regards,
Albert He

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

 

 

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information or anything not related to the issue or question.

If you are unsure how to upload data 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.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors