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

Rolling 6 Month Average Column Chart

Hello, I'm hoping to create a column chart with 12 months of data displayed for the past year (June 21 - July 20). Each column would display an average of that month and the 5 months preceding it (June '21 column would be average of Jan '21-June '21). Ideally this would be visually set up so 2021 months are one color and 2020 columns are another. Is this achievable with measures or another method? Thank you!

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @pstp ;

Base on my understand; if you want to calucate avgerge of  last 6 month (such as  1.21-6.21),you could create a measure as follows:

Avg =
VAR _datedif =
    DATEDIFF ( MAX ( [Date ] ), EOMONTH ( MAX ( [Date ] ), 0 ), DAY )
RETURN
    CALCULATE (
        AVERAGE ( [AtdSum] ),
        FILTER (
            ALL ( 'Table' ),
            [Date ] <= MAX ( [Date ] )
                && [Date ]
                    >= EOMONTH ( [Date ], -5 ) - _datedif
        )
    )

 If you want to display different colors according to the year, you can create another measure and apply the conditional format as shown in the figure:

flag= IF(YEAR(MAX([Date ]))=2020,1,0)

vyalanwumsft_0-1624434701006.pngvyalanwumsft_1-1624434711472.png

The final output is shown below:

vyalanwumsft_2-1624434860061.png

If it's not right, please  provide more logic and share a simple sample file without any sesentive information.

Best Regards,
Community Support Team_ Yalan Wu
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

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi, @pstp ;

Base on my understand; if you want to calucate avgerge of  last 6 month (such as  1.21-6.21),you could create a measure as follows:

Avg =
VAR _datedif =
    DATEDIFF ( MAX ( [Date ] ), EOMONTH ( MAX ( [Date ] ), 0 ), DAY )
RETURN
    CALCULATE (
        AVERAGE ( [AtdSum] ),
        FILTER (
            ALL ( 'Table' ),
            [Date ] <= MAX ( [Date ] )
                && [Date ]
                    >= EOMONTH ( [Date ], -5 ) - _datedif
        )
    )

 If you want to display different colors according to the year, you can create another measure and apply the conditional format as shown in the figure:

flag= IF(YEAR(MAX([Date ]))=2020,1,0)

vyalanwumsft_0-1624434701006.pngvyalanwumsft_1-1624434711472.png

The final output is shown below:

vyalanwumsft_2-1624434860061.png

If it's not right, please  provide more logic and share a simple sample file without any sesentive information.

Best Regards,
Community Support Team_ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

amitchandak
Super User
Super User

@pstp , with help from a date table try measures like

 

Rolling 6 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX('Date'[Date ]),-6,MONTH))

 

or

 

Rolling 6 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],eomonth(MAX('Date'[Date ]),0),-6,MONTH))

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

@amitchandak Thank you for responding. I've gotten that far and have a calculation working like that. What I'm stuck on is displaying the same calculation for multiple dates. Included below is the simple data set I'm working with and the desired look of the visual. 

 

 

dataset1.jpgdesiredvisual1.jpg

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.