## Desktop

Regular Visitor
Posts: 19
Registered: ‎11-29-2016

# Card to display last 5 days average

I have a page with date slicers to select year(s), month(s) and YearWeeks, and my line chart is working great.

Now I want to add a Card next to the line chart that displays the average value of the last 5 days that are currently displayed in the line chart.

How do I approach this?  Is it done via a measure, a column or a combination?

Thank you.

Accepted Solutions
Highlighted
Super Contributor
Posts: 3,609
Registered: ‎09-27-2016

## Re: Card to display last 5 days average

Hi @SCTDev,

First, please create a measure to calculate the last day in calendar slicer using the formula below.

`MAX in selected date = MAXX(ALLSELECTED(Test),Test[Date])`

Then create a slicer including the date, and create a card display the last five days' average.

`last5days_average1 = DIVIDE(CALCULATE(SUM(Test[Value]),FILTER(Test,AND(Test[Date]<=Test[MAX in selected date],Test[Date]>(Test[MAX in selected date]-5)))),5)`

If you have any other question, please let me know.

Best Regards,
Angelia

All Replies
Super Contributor
Posts: 3,609
Registered: ‎09-27-2016

## Re: Card to display last 5 days average

Hi @SCTDev,

I try to reproduce your scenario, and get expected result as followings. The first screenshot is the sample data.

Then I create a measure to calculate the last 5 days average, and create a lie chart display, please select the measure as values level, please see the result in second snapshot.

`last5days_average = DIVIDE(CALCULATE(SUM(Test[Value]),FILTER(ALL(Test),AND(Test[Date]<=MAX(Test[Date]),Test[Date]>(MAX(Test[Date])-5)))),5)`

For instance, for 2016/1/7, the measure will calculate the average during 2016/1/2-2016/1/7, for 2016/1/8, the measure will calculate the average during 2016/1/3-2016/1/8.

If you have any other issue, please feel free to ask.

Best Regards,
Angelia

Regular Visitor
Posts: 19
Registered: ‎11-29-2016

## Re: Card to display last 5 days average

[ Edited ]

Angelia ( @v-huizhn-msft ),

This is a very good example, but it is not exactly what I am looking for.  Let's use your data to work toward my goal.

If I add a calendar slicer to select the days and choose 1/1/2016 through 1/12/2016, I would want the following to appear:

1. A chart similar to the one you display, but instead of displaying the calculated measure 5 day average, show the actual values.  That is simple and I have that working.

2. A separate Card visualization that displays the calculated measure 5 day average ONLY for the last day in the calendar slicer range.  In this case, it would be the calculation for 1/12/2016, which would be the average of (32+46+32+29+10)/5 = 29.8.  I want the card to only display 29.8.  I do not want a line to show the 5 day average over time.  If slice from 1/1 to 1/11, I want the card to display (50+32+46+32+29)/5 = 37.8.

So my question is, how do I tell the card to display the single value of 29.8 (the 5 day average associated with the last date sliced)?

Thank you for your help!

Highlighted
Super Contributor
Posts: 3,609
Registered: ‎09-27-2016

## Re: Card to display last 5 days average

Hi @SCTDev,

First, please create a measure to calculate the last day in calendar slicer using the formula below.

`MAX in selected date = MAXX(ALLSELECTED(Test),Test[Date])`

Then create a slicer including the date, and create a card display the last five days' average.

`last5days_average1 = DIVIDE(CALCULATE(SUM(Test[Value]),FILTER(Test,AND(Test[Date]<=Test[MAX in selected date],Test[Date]>(Test[MAX in selected date]-5)))),5)`

If you have any other question, please let me know.

Best Regards,
Angelia