Forum Discussion
Flexible line chart x-axis
maracles - Try the combined Column and Line chart, that allows you to have your own hierarchy and it works for a line graphic, just don't put anything in your Column area.
maracles Greg_Deckler Even if this is the expertise of SqlJason and probably have a better solution this is what I came up.
maracles You are right on needing two charts the one over the other. When you select a single month the days chart will show and if there are multiple ( meaning no filter or more selected than one ) the other visual with show up.
Let's start.
Assumimng you are using a calendar/date table as dimension.
Assuming that the measure you display called [Sales]
Create one line chart and add months ( I use MonthInCalendar column i.e "Jan 2015" ) in axis..
Create second line chart and add days ( I use Datekey column ) in axis.. ( or copy the first one so you have the same formating & size )
Remove titles.
In the first chart ( months ) add the following measure
Axis Months = VAR AllMonths = CALCULATE ( DISTINCTCOUNT ( 'Calendar'[MonthInCalendar] ); ALLSELECTED ( 'Calendar' ) ) VAR Months = DISTINCTCOUNT ( 'Calendar'[MonthInCalendar] ) RETURN IF ( Months <> AllMonths; [Sales] )
Variable Months always return 1 since the current filter context is one month due to months in axis.
Variable Allmonths returns the number of months in calendar table ignoring the current filter context months in axis ) BUT not any other filter we select outside the graph..( not preciesly - from more details check ALLSELCTED() http://www.sqlbi.com/articles/understanding-allselected/
Result if we don't select one month in a slicer or other chart our line will be visible...If we select one then the chart shows nothing...Cool
Now in the second chart (days ) add the following
Axis Days= VAR AllMonths = CALCULATE ( DISTINCTCOUNT ( 'Calendar'[MonthInCalendar] ); ALLSELECTED ( 'Calendar' ) ) VAR Months = DISTINCTCOUNT ( 'Calendar'[MonthInCalendar] ) RETURN IF ( Months = AllMonths; [Sales] )
The same as the previous but know the line is visible only if we have a month selected in slicer or other chart. (due to the Moths = Allmonths)
Now put one into other so it looks like one. Depending what you select in months one of them will be visible ,mimic the change in axis.
(red months in axis - green days in axis )
Plus : You can change color in one graph or other attributes the change in axis is more visible
Minus: when you hoove over with the mouse tooltip only appears for the chart the Z-Score in the front and when this is blank hoovering over blurs the chart.
Hope this can work for you..
P.S. I did enjoy trying to fing the workaround
- maracles10 years ago
Resolver II
Thanks Konstantinos for taking the time to look into this. I was actually hoping to have both years plotted on a single chart rather than one split, I am however going to explore your suggestions as it may be another way of achieveing what we are looking for. Before I can try out your method I am actualy having a different line chart related issue that I am about to post about. Will update this post once I have tested it though.