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

Last 12 Months not affected by date filter

Hello, I'm trying to get a rolling 12 month average.  I need to first sum the month and then average the 12 months from there.  For example, the average for the table below should be $121,955,757.71.  Instead I keep getting $60,977,878.86 (the average of all the numbers together).  I can't seem to figure it out.  Thank you!

 

BA11501Banderso_0-1651577210764.png

 

1 ACCEPTED SOLUTION

Hi @BA11501Banderso,

 

Please try this code:

Measurde =
VAR _s =
    DATE ( SELECTEDVALUE ( 'Table'[Date].[Year] ), SELECTEDVALUE ( 'Table'[Date].[MonthNo] ) - 11, 1 )
VAR _e =
    DATE ( SELECTEDVALUE ( 'Table'[Date].[Year] ), SELECTEDVALUE ( 'Table'[Date].[MonthNo] ) + 1, 1 ) - 1
RETURN
    AVERAGEX (
        TOPN (
            12,
            SUMMARIZE (
                FILTER ( ALL ( 'Table' ), [Date] >= _s && [Date] <= _e ),
                [Date],
                "sum", SUM ( 'Table'[Amount] )
            ),
            [Date], DESC
        ),
        [sum]
    )

Result:

vchenwuzmsft_0-1651820613265.png

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

11 REPLIES 11
BA11501Banderso
Frequent Visitor

AccountAsset ItemAmountDate
100Widget144,781.482/28/2021
100Widget144,781.481/31/2021
100Widget144,781.484/30/2021
100Widget144,781.483/31/2021
100Widget144,781.486/30/2021
100Widget144,781.485/31/2021
100Widget144,781.488/31/2021
100Widget144,781.487/31/2021
100Widget144,781.4810/31/2021
100Widget144,781.489/30/2021
100Widget144,781.4811/30/2021
100Widget144,781.4812/31/2021
200Widget2121,606,727.552/28/2021
200Widget2121,606,634.101/31/2021
200Widget2121,600,443.754/30/2021
200Widget2121,588,370.183/31/2021
200Widget2121,602,452.296/30/2021
200Widget2121,600,498.675/31/2021
200Widget2122,132,385.948/31/2021
200Widget2122,122,859.257/31/2021
200Widget2122,166,275.5710/31/2021
200Widget2122,167,506.029/30/2021
200Widget2122,357,357.2111/30/2021
200Widget2122,380,204.2612/31/2021

 

Here it is.  Thank you!

@BA11501Banderso 

First calculate these two columns:

- Month = FORMAT('Table'[Date],"MMMM")

- Year = YEAR('Table'[Date])

Then, use this measure to obtain your result:

AVG =
VAR countmonth = CALCULATE(DISTINCTCOUNT('Table'[Month]), ALLEXCEPT('Table', 'Table'[Year]))
RETURN CALCULATE(SUM('Table'[ Amount ]), ALLEXCEPT('Table', 'Table'[Year])) / countmonth

 

BF

So I'm looking for a rolling average.  This seems to just populates the total number into each month.  I guess it would be better is I gave you more than 12 months of data...

 

BA11501Banderso_0-1651595726921.png

 

 

AccountAsset ItemAmountDate
100Widget144,781.482/28/2021
100Widget144,781.481/31/2021
100Widget144,781.484/30/2021
100Widget144,781.483/31/2021
100Widget144,781.486/30/2021
100Widget144,781.485/31/2021
100Widget144,781.488/31/2021
100Widget144,781.487/31/2021
100Widget144,781.4810/31/2021
100Widget144,781.489/30/2021
100Widget144,781.4811/30/2021
100Widget144,781.4812/31/2021
200Widget2121,606,727.552/28/2021
200Widget2121,606,634.101/31/2021
200Widget2121,600,443.754/30/2021
200Widget2121,588,370.183/31/2021
200Widget2121,602,452.296/30/2021
200Widget2121,600,498.675/31/2021
200Widget2122,132,385.948/31/2021
200Widget2122,122,859.257/31/2021
200Widget2122,166,275.5710/31/2021
200Widget2122,167,506.029/30/2021
200Widget2122,357,357.2111/30/2021
200Widget2122,380,204.2612/31/2021
100Widget144,781.482/28/2022
100Widget144,781.481/31/2022
100Widget144,781.484/30/2022
100Widget144,781.483/31/2022
100Widget144,781.486/30/2022
100Widget144,781.485/31/2022
100Widget144,781.488/31/2022
100Widget144,781.487/31/2022
100Widget144,781.4810/31/2022
100Widget144,781.489/30/2022
100Widget144,781.4811/30/2022
100Widget144,781.4812/31/2022
200Widget2121,606,727.552/28/2022
200Widget2121,606,634.101/31/2022
200Widget2121,600,443.754/30/2022
200Widget2121,588,370.183/31/2022
200Widget2121,602,452.296/30/2022
200Widget2121,600,498.675/31/2022
200Widget2122,132,385.948/31/2022
200Widget2122,122,859.257/31/2022
200Widget2122,166,275.5710/31/2022
200Widget2122,167,506.029/30/2022
200Widget2122,357,357.2111/30/2022
200Widget2122,380,204.2612/31/2022

@BA11501Banderso Sorry, a mistake in the measure, set Month with Year in the return, like this:

 

AVG =
VAR countmonth = CALCULATE(DISTINCTCOUNT('Table'[Month]), ALLEXCEPT('Table', 'Table'[Year]))
RETURN CALCULATE(SUM('Table'[ Amount ]), ALLEXCEPT('Table', 'Table'[Month], 'Table'[Year])) / countmonth

 

BF

That doesn't appear to be giving me what I'm looking for.  That appears to give me the total for the month divided by 12. 

 

BA11501Banderso_0-1651596542696.png

 

I'm looking to sum the months individually (multiple inputs into each month) and then take an average of the total of the prior 12 months.

@BA11501Banderso can you paste a table with the expected result? To better understand

Thx

BF

Yup,  I'd like it to look something like this...

DateActual Monthly AmountLast Twelve Months
1/1/2021     121,651,415.58           121,651,415.58
2/1/2021     121,651,509.03           121,651,462.31
3/1/2021     121,633,151.66           121,645,358.76
4/1/2021     121,645,225.23           121,645,325.38
5/1/2021     121,645,280.15           121,645,316.33
6/1/2021     121,647,233.77           121,645,635.90
7/1/2021     122,167,640.73           121,720,208.02
8/1/2021     122,177,167.42           121,777,327.95
9/1/2021     122,212,287.50           121,825,656.79
10/1/2021     122,211,057.05           121,864,196.81
11/1/2021     122,402,138.69           121,913,100.62
12/1/2021     122,424,985.74           121,955,757.71
1/1/2022     121,609,134.10           121,952,234.26
2/1/2022     121,651,509.03           121,952,234.26
3/1/2022     121,592,170.18           121,948,819.13
4/1/2022     121,645,225.23           121,948,819.13
5/1/2022     121,645,498.67           121,948,837.34
6/1/2022     121,445,447.48           121,932,021.82
7/1/2022     122,167,640.73           121,932,021.82
8/1/2022     122,184,385.94           121,932,623.36
9/1/2022     122,178,506.02           121,929,808.24
10/1/2022     118,045,381.48           121,582,668.61
11/1/2022     122,402,138.69           121,582,668.61
12/1/2022     122,424,985.74           121,582,668.61

 

24 months of data

Asset ItemAmountDate
Widget144,781.482/28/2021
Widget144,781.481/31/2021
Widget144,781.484/30/2021
Widget144,781.483/31/2021
Widget144,781.486/30/2021
Widget144,781.485/31/2021
Widget144,781.488/31/2021
Widget144,781.487/31/2021
Widget144,781.4810/31/2021
Widget144,781.489/30/2021
Widget144,781.4811/30/2021
Widget144,781.4812/31/2021
Widget2121,606,727.552/28/2021
Widget2121,606,634.101/31/2021
Widget2121,600,443.754/30/2021
Widget2121,588,370.183/31/2021
Widget2121,602,452.296/30/2021
Widget2121,600,498.675/31/2021
Widget2122,132,385.948/31/2021
Widget2122,122,859.257/31/2021
Widget2122,166,275.5710/31/2021
Widget2122,167,506.029/30/2021
Widget2122,357,357.2111/30/2021
Widget2122,380,204.2612/31/2021
Widget144,781.482/28/2022
Widget12,500.001/31/2022
Widget144,781.484/30/2022
Widget13,800.003/31/2022
Widget144,781.486/30/2022
Widget145,000.005/31/2022
Widget152,000.008/31/2022
Widget144,781.487/31/2022
Widget144,781.4810/31/2022
Widget111,000.009/30/2022
Widget144,781.4811/30/2022
Widget144,781.4812/31/2022
Widget2121,606,727.552/28/2022
Widget2121,606,634.101/31/2022
Widget2121,600,443.754/30/2022
Widget2121,588,370.183/31/2022
Widget2121,400,666.006/30/2022
Widget2121,600,498.675/31/2022
Widget2122,132,385.948/31/2022
Widget2122,122,859.257/31/2022
Widget2118,000,600.0010/31/2022
Widget2122,167,506.029/30/2022
Widget2122,357,357.2111/30/2022
Widget2122,380,204.2612/31/2022

 

Thank you!

Hi @BA11501Banderso,

 

Please try this code:

Measurde =
VAR _s =
    DATE ( SELECTEDVALUE ( 'Table'[Date].[Year] ), SELECTEDVALUE ( 'Table'[Date].[MonthNo] ) - 11, 1 )
VAR _e =
    DATE ( SELECTEDVALUE ( 'Table'[Date].[Year] ), SELECTEDVALUE ( 'Table'[Date].[MonthNo] ) + 1, 1 ) - 1
RETURN
    AVERAGEX (
        TOPN (
            12,
            SUMMARIZE (
                FILTER ( ALL ( 'Table' ), [Date] >= _s && [Date] <= _e ),
                [Date],
                "sum", SUM ( 'Table'[Amount] )
            ),
            [Date], DESC
        ),
        [sum]
    )

Result:

vchenwuzmsft_0-1651820613265.png

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

 

This is AWESOME!  Thank you!!

@BA11501Banderso 

With this measure i achieve the correct result for 2021, but i didn't understand what it have to do with the new year (2022), can you explain?

 

In this row: 

1/1/2022      121,609,134.10            121,952,234.26

 

How to you calculate the expected value?

 

The measure:

Cumulative_Actual =
VAR countmonths = CALCULATE (
DISTINCTCOUNT( 'Table'[Month]),
filter( ALL ( 'Table'[Date]),
'Table'[Date] <= MAX( 'Table'[Date] ))
)
RETURN CALCULATE (
SUM ('Table'[ Amount ] ),
filter( ALL ( 'Table'[Date]),
'Table'[Date] <= MAX( 'Table'[Date] ))
) / countmonths

 

BF

BeaBF
Impactful Individual
Impactful Individual

@BA11501Banderso Hi!

 

Can you paste your data instead of the picture?

 

Thx,

BF

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors