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
Eiji77
Helper II
Helper II

I want to calculate the three-month average of the current month and the previous and next month.

I want to calculate the three-month average of the current month and the previous and next month.

 

How do I make a Dax?

I want to help.

スクリーンショット (140).png

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi Eiji77,

Below is my design:

month amount
7/1/2017 100
8/1/2017 200
9/1/2017 100
10/1/2017 300
7/1/2018 100
8/1/2018 500
9/1/2018 150
10/1/2018 250
7/1/2019 200
8/1/2019 300
9/1/2019 100
10/1/2019 200

create a measure like below

Measure 6 =
CALCULATE (
    AVERAGE ( 'avg'[amount] ),
    FILTER (
        ALL ( 'avg' ),
        YEAR ( 'avg'[month] ) = YEAR ( MIN ( 'avg'[month] ) )
            && MONTH ( 'avg'[month] )
                >= MONTH ( MIN ( 'avg'[month] ) ) - 1
            && MONTH ( 'avg'[month] )
                <= MONTH ( MIN ( 'avg'[month] ) ) + 1
    )
)

299.PNG

Best Regards,
Zoe Zhi

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

View solution in original post

5 REPLIES 5
Mariusz
Community Champion
Community Champion

Hi @Eiji77 

 

You can try something like below.

Measure = 
VAR _start = FIRSTDATE( DATEADD( 'Table'[Date], -1, MONTH ) )
VAR _end =  LASTDATE( DATEADD( 'Table'[Date], 1, MONTH ) ) 
RETURN 
    CALCULATE( 
        AVERAGE('Table'[Value]) , 
        DATESBETWEEN( 'Table'[Date], _start, _end )
    ) 
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski



Thank you @Mariusz ,

 

However, the results are now attached.

Do you know why this happened?

 

タイトルなし.png

@Mariusz ,This is possible with a simple test model, but not with my model.タイトルなし.png

Mariusz
Community Champion
Community Champion

Hi @Eiji77 

Try something like below.

AVG = 
VAR _start = FIRSTDATE( DATEADD( 'Table'[Date], -1, MONTH ) )
VAR _end =  LASTDATE( DATEADD( 'Table'[Date], 1, MONTH ) ) 
VAR _tbl = 
CALCULATETABLE( 
    'Table',
    ALL( 'Table' ),
    DATESBETWEEN( 'Table'[Date], _start, _end ) 
) 
VAR _months = 
GROUPBY(
    _tbl,
    'Table'[Year Month] ,
    "sum", SUMX( CURRENTGROUP(), 'Table'[Value] ) 
)
RETURN 
AVERAGEX( _months, [sum] )

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
Mariusz Repczynski

 

dax
Community Support
Community Support

Hi Eiji77,

Below is my design:

month amount
7/1/2017 100
8/1/2017 200
9/1/2017 100
10/1/2017 300
7/1/2018 100
8/1/2018 500
9/1/2018 150
10/1/2018 250
7/1/2019 200
8/1/2019 300
9/1/2019 100
10/1/2019 200

create a measure like below

Measure 6 =
CALCULATE (
    AVERAGE ( 'avg'[amount] ),
    FILTER (
        ALL ( 'avg' ),
        YEAR ( 'avg'[month] ) = YEAR ( MIN ( 'avg'[month] ) )
            && MONTH ( 'avg'[month] )
                >= MONTH ( MIN ( 'avg'[month] ) ) - 1
            && MONTH ( 'avg'[month] )
                <= MONTH ( MIN ( 'avg'[month] ) ) + 1
    )
)

299.PNG

Best Regards,
Zoe Zhi

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

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.