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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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.


Go to My LinkedIn Page


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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