Forum Discussion
dynamic x-axis based on filter
- 1 month ago
Hi alops194
are you looking for a solution similar to this ?
you can follow this tutorial to get a dynamic x axis https://www.youtube.com/watch?v=hilfglpKNRQ
I have attached a sample I created so you can play around with it and get it working as needed.
Create a field parameter with month-year and week-year as the members, and use that on the axis of the chart.
Create a measure like
TopN Filter =
VAR CurrentSelection =
SELECTEDVALUE ( 'Parameter'[Parameter Order] )
// Assume that 0 = Week Year, 1 = Month Year
VAR WeekIsFiltered =
CALCULATE (
ISFILTERED ( 'Date'[Week Year] ),
ALLSELECTED ( 'Date'[Week Year] )
)
VAR Result =
SWITCH (
TRUE (),
CurrentSelection = 0 && WeekIsFiltered, 1,
CurrentSelection = 1, 1,
0
)
RETURN
Result
Apply that as a Top N filter on the field parameter in the chart visual. Set it to show only the top 1 items.
Thanks a lot, I'm close to the solution. I created the measure as you told me. I just changed 0 and 1 based on my parameters fields. The only thing I need to fix is that when I filter the week, the change on the x-axis occurs correctly, but the label it displays is concatenated "month-year week-year" and this can also be seen from the graph title. How can I fix this?
- johnt751 month agoSuper User
I think the easiest way to fix the x-axis would be to turn the x-axis title off, and you should be able to edit the chart title manually.
Worth noting that when I've used this technique in the past I applied the Top N filter directly on the parameter rather than on the parameter order. I don't think that would make a difference, but it could be worth trying.
- alops1941 month agoFrequent Visitor
Yes, the solution is simple on the title, the problem is on the value in this I would like to only display the week year and not the concatenation with the month
- johnt751 month agoSuper User
What do you have in the X-axis of the chart? It should just be the parameter field from your field parameter table.