Forum Discussion
powerbiexpert22
1 year agoImpactful Individual
dynamic line chart
i have a line chart showing monthly sales . if i click on any month in the line chart , it should display the sales for that selected month along with the previous two months (same as line chart) a...
burakkaragoz
1 year agoSuper User
Hi powerbiexpert22 ,
You can achieve this behavior using a combination of DAX and a disconnected Date table.
Here’s the general idea:
- Create a disconnected Date table (if you don’t already have one).
- Use a measure that checks if a month is selected, and if so, filters the data to include that month and the two months before it.
Example DAX:
Sales (Selected + Prev 2 Months) =
VAR SelectedMonth =
SELECTEDVALUE('Date'[MonthYear]) -- assuming MonthYear is like "2024-03"
VAR SelectedDate =
CALCULATE(MAX('Date'[Date]), 'Date'[MonthYear] = SelectedMonth)
VAR StartDate = EDATE(SelectedDate, -2)
RETURN
CALCULATE(
[Total Sales],
FILTER(
ALL('Date'),
'Date'[Date] >= StartDate &&
'Date'[Date] <= SelectedDate
)
)This way:
- When a month is selected, it shows that month + 2 previous months.
- When nothing is selected, it shows all months (default behavior of the visual).
Let me know if you need help adapting this to your model.
If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.
translation and formatting supported by AI
- powerbiexpert221 year agoImpactful Individual
Hi burakkaragoz ,
I have tried your approach as well however nothing is happening once i click on any data point on visual
please see below pbix
https://drive.google.com/file/d/1NR3WBeQW8dwXOdCN3opuzF6-jhVlg6XQ/view?usp=drive_link