cancel
Showing results for
Did you mean:

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Anonymous
Not applicable

## Moving X axis based on Month selected

I am trying to create a line chart that varies with slicer selected. Let me explain briefly

I have created measures as follows:

Period Start Dates_Dim = FIRSTDATE( DATESINPERIOD(Dates_Dim[Date], [Period End Dates_dim], -3, MONTH))
Period End Dates_dim = LASTDATE(Dates_Dim[Date])
R12 Period Start Dates_Dim = FIRSTDATE( DATESINPERIOD(Dates_Dim[Date], [Period End Dates_dim], -12, MONTH))

Rolling 12 Month Average Dates_Dim = divide(CALCULATE(SUM(Oracle_Order_Management[Sales]),DATESBETWEEN ( Dates_Dim[Date], [R12 Period Start Dates_Dim], [Period End Dates_dim] )),12,0)

Rolling 3 Month Average Dates_Dim = divide(CALCULATE(SUM(Oracle_Order_Management[4WE Quantity]),DATESBETWEEN ( Dates_Dim[Date], [Period Start Dates_Dim], [Period End Dates_dim] )),3,0)

Now in Line chart i have added Month_Name as Axis, Products in Legend and Rolling 3 Month Average Dates_Dim as values.
------------------------------------------------------------------------------------------------------------------------------------------

But what i need is i need to display rolling 3 months avg or rolling 12 months average based on Slicer. Even that i was able to achieve. Now next hurdle is making the X axis change dynamically with month selected. If i select march i should see average as jan+feb+mar. So i need everyhting to work together, R3M VS R12M slicer along with Month Year Slicer

I can provide sample PBIX file if that would make life easy.
3 REPLIES 3
Super User

Hi,

Share some data and show the expected result.  As of now, don't bother about the visual.  For the data that you share, just show your actual expected result in a Table.  Once the numbers in the Table appear OK, we can alsoways switch to any visual.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Super User

Try like this.

These formulae will change based on the slicer. the date is date dimension here.

``` Sales 12 month = (
VAR _Curr_END = Max('Date'[Date])
return
calculate(sum(Sales[Sales Amount]),Sales[Sales Date] >= _Cuur_start && Sales[Sales Date] <=  _Curr_END )
)

Sales 3 month = (
VAR _Curr_END = Max('Date'[Date])
return
calculate(sum(Sales[Sales Amount]),Sales[Sales Date] >= _Cuur_start && Sales[Sales Date] <=  _Curr_END )
)```

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks.

My Recent Blog - https://community.powerbi.com/t5/Community-Blog/Comparing-Data-Across-Date-Ranges/ba-p/823601

Anonymous
Not applicable

@amitchandak Did not work. When i selected august the line chart shows values as dots, where as i wanted the line chart to display march to august in X axis and every month show 3 months average

Announcements

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

#### Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors