I need to show a trendline for a moving average but only for selected date ranges how can I do this

0 votes

I need to show a trendline for a moving average but only for selected date ranges—how can I do this?
I need to create a moving average trendline in Power BI that adjusts dynamically based on a user-selected date range. The trendline should update when users filter specific periods while maintaining accuracy in calculations. What is the best approach using DAX and time intelligence functions to ensure the moving average reflects only the selected dates?

4 days ago in Power BI by Evanjalin
• 20,980 points
22 views

1 answer to this question.

0 votes

To do a Moving Average Trendline that will keep on updating dynamically according to the user-selected date range in Power BI, do the following:

1. Create a Moving Average Measure

DAX is used to calculate moving averages based on the specified time frame, such as 7-day or 30-day averages.

MovingAvg =  
VAR DaysBack = 7  
RETURN  
AVERAGEX(  
    DATESINPERIOD(  
        'Date'[Date],  
        MAX('Date'[Date]),  
        -DaysBack, DAY  
    ),  
    CALCULATE(SUM('Sales'[SalesAmount]))  
)

Modify DaysBack as per the required period, e.g., -30 for a 30-day moving average.

2. Enable Dynamic Date Filtering

Whenever the users filter a specific date range as per their requirement through the slicers, Power BI manages to dynamically filter the MAX('Date'[Date]) in the DAX formula. Therefore, this makes sure that the moving average applies only to the range selected.

3. Charting the Trendline

Use a line chart with Date along the X-axis and MovingAvg against the Y-axis and overlay the same with actuals for comparison.

answered 4 days ago by anonymous
• 20,980 points

Related Questions In Power BI

0 votes
1 answer

I need to calculate a running total but reset it at the start of each new quarter—how can I achieve this in DAX?

To calculate a running total that resets ...READ MORE

answered Mar 7 in Power BI by anonymous
• 20,980 points
66 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How do I configure a read-only user for PostgreSQL in Power BI to maintain security?

To configure a read-only user for PostgreSQL ...READ MORE

answered Feb 28 in Power BI by anonymous
• 20,980 points
55 views
+2 votes
0 answers

Assume referential integrity

1) What is Assume referential integrity? what ...READ MORE

Aug 19, 2019 in Power BI by vnk
1,947 views
+2 votes
1 answer

If Condition

DAX - I assume [Claim_line].[Allowed_Amount_B6] is one ...READ MORE

answered Aug 20, 2019 in Power BI by anonymous
• 33,050 points
1,749 views
+2 votes
1 answer

How to export data to CSV from power bi embedded url ?

Hi Arathi, You can open Visuals from embedded ...READ MORE

answered Aug 23, 2019 in Power BI by anonymous
• 33,050 points
6,794 views
+1 vote
1 answer

Power Bi to Machine Learning Model

Hello @vnk! Power BI only supports Azure Machine ...READ MORE

answered Dec 3, 2019 in Power BI by Priyanka
1,326 views
0 votes
1 answer

I need to compute a year-over-year (YoY) growth rate but only for months where I have data in both years—how do I do this?

Calculating Year-over-Year (YoY) growth only for those ...READ MORE

answered Mar 10 in Power BI by anonymous
• 20,980 points
47 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP