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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
ntdanh
Frequent Visitor

Rolling average - How to cut the start point and end point of line

Dear Community,

 

Could you help me to adjust the DAX formula oF Rolling Avg 2Q yellow line to exclude the start point which is not enough data (2 quarter ) to calculate properly and the end point (2023Q2) as below ?

 

 

ntdanh_0-1681354405049.png

 

Rolling Avg 2Q = 
    VAR NumOfQuarters = 2
    VAR LastCurrentDate =
        MAX(DimDates[Date])
    VAR Period =
        DATESINPERIOD (DimDates[Date], LastCurrentDate, - NumOfQuarters, QUARTER )
    
    VAR Result = 
        CALCULATE (
           'Value/Qty Selection'[Value/Quantity]
            /2,
            Period
        )
   

RETURN
         Result

 

1 REPLY 1
Jihwan_Kim
Super User
Super User

Hi,

I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

I hope the below can provide some ideas on how to create a solution for your  datamodel.

 

Jihwan_Kim_0-1681356142121.png

 

Jihwan_Kim_1-1681357172728.png

 

Qty total: = 
SUM( Sales[Quantity] )

 

Qty 2months rolling avg: =
VAR _currentrowquarterend =
    MAX ( 'Calendar'[End of Quarter] )
VAR _conditiontable =
    FILTER (
        ADDCOLUMNS (
            FILTER (
                ALL ( 'Calendar'[End of Quarter], 'Calendar'[Year-Quarter] ),
                'Calendar'[End of Quarter] <= _currentrowquarterend
            ),
            "qty", [Qty total:]
        ),
        [qty] <> BLANK ()
    )
VAR _condition =
    COUNTROWS ( _conditiontable ) >= 2
        && [Qty total:] <> BLANK ()
        && HASONEVALUE ( 'Calendar'[Year-Quarter] )
RETURN
    DIVIDE ( _condition, _condition )
        * CALCULATE (
            [Qty total:],
            WINDOW (
                -1,
                REL,
                0,
                REL,
                ALL ( 'Calendar'[End of Quarter], 'Calendar'[Year-Quarter] ),
                ORDERBY ( 'Calendar'[End of Quarter], ASC )
            )
        ) / 2

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

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.