Forum Discussion
Dynamic Dates for 13-Month Trend
Hi -
I am attempting to get a dynamic 13-month trend that will update based on the date I select in a drop-down.
For example, when I select February 2025, I want the trend to show February 2024-February 2025 or when I select January 2025, I want to see January 2024 - January 2025, etc.
I can't use a date range filter due to other visuals on the page that are only for the specific reporting month. Also I don't want to allow free range filter, only 13 months back from the month selected.
Based on some googling / copilot help I completed the following steps, but the range is still not coming through correctly. Any help greatly appreciated!
Step 1: Create SelectedMonth Measure on 'Calendar' Table
Step 2: Create SelectMonthColumn
Hi,
I have solved a similar question in the attached PBI file.
8 Replies
- DataInsights
Super User
abd8,
The calculated table you created in step 5 is unable to recognize user-specified filters in Report view (e.g., slicers). See link below for a dynamic solution:
https://www.sqlbi.com/articles/show-previous-6-months-of-data-from-single-slicer-selection/
- abd8Regular Visitor
This is very helpful. However, when I try to implement that code, I'm getting this error:
USERELATIONSHIP function can only use the two columns references participating in relationship.
I did tweak it slightly for my use case, so that may be what's causing it:
13_Month_Trend =VAR NumOfMonths = -13VAR ReferenceDate = 'Calendar'[SelectedMonth]VAR PreviousDates =DATESINPERIOD ('Previous Date'[Date],ReferenceDate,NumOfMonths,MONTH)VAR Result =CALCULATE (SELECTEDMEASURE (),REMOVEFILTERS ( 'Calendar' ),KEEPFILTERS ( PreviousDates ),USERELATIONSHIP ( 'Previous Date'[Date], 'Calendar'[SelectedMonthColumn] ))RETURN Result- DataInsights
Super User
abd8,
Verify the columns in the relationship between 'Previous Date' and 'Calendar'. The columns in the relationship should be used in the USERELATIONSHIP function.
- abd8Regular Visitor
I also noticed that the date range is different depending on whether I display as just the date or the date hierarchy. Does anyone know why this may be?
- v-saisrao-msft
Community Support
Hi abd8,
I wanted to check if you had the opportunity to review the information provided by Ashish_Mathur. Please feel free to contact us if you have any further questions. If the response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.
- Ashish_Mathur
Super User
Hi,
I have solved a similar question in the attached PBI file.