Forum Discussion
Dynamic change in X Axis
Hello Everyone,
I am trying a scenario where I need one chart, and it should shows two visuals like sales(YOY) by year and sales(YOY) by area.
The x-axis should be change by using Slicer which have two values Year and Area.
Is there any way to achieve this. I don't need any alternatives for that like drill down etc. I need that exact thing to be done.
If it is possible by dax please suggest something. (I am trying different dax functions to solve this problem but don't know what exact function should be used to do this.)
Thanks,
Akash Singhal
Hi singhal14
Here's one idea of how it can be done using a bridging table.
Could well be other ways of handling this :)
- Assuming you have Region and Year lookup tables, create a RegionYear table which is the cross product of Region & Year tables.
- Duplicate each row of RegionYear and add an Axis Dimension column which is "Region" for half the rows and "Year" for the other half, and an Axis Value column which is the Region or Year value for each row (depending on the Axis Dimension value).
- Relate Year and Region to RegionYear using inactive bidirectional relationships:
- Create an Axis Dimension Selected measure to harvest the value of Axis Dimension. Something equivalent to this (this guards against multiple selection):
Axis Dimension Selected = IF ( ISFILTERED ( RegionYear[Axis Dimension] ), IF ( CALCULATE ( HASONEVALUE ( RegionYear[Axis Dimension] ), ALLSELECTED () ), VALUES ( RegionYear[Axis Dimension] ) ) ) - Create a Sales Amount Flexible Axis measure like this (assuming Sales Amount is the normal measure):
Sales Amount Flexible Axis = IF ( NOT ( ISBLANK ( [Axis Dimension Selected] ) ), SWITCH ( [Axis Dimension Selected], "Region",
CALCULATE ( [Sales Amount], USERELATIONSHIP ( RegionYear[Region], Region[Region] ) ), "Year",
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( RegionYear[Year], 'Year'[Year] )
) )
) - Then you can create visualizations using RegionYear[Axis Value] and [Sales Amount Flexible Axis]
17 Replies
- uriaAdvocate I
There is a better solution in this blog :
http://tinylizard.com/dynamically-changing-chart-axis/
The only change is because we use Power BI we can enable the filtering in both directions , so we dont need any complex measure.
- AnonymousNot applicable
Hi singhal14,
>>I am trying a scenario where I need one chart, and it should shows two visuals like sales(YOY) by year and sales(YOY) by area.
The x-axis should be change by using Slicer which have two values Year and Area
According to your description, you want to use slicer to choose which column displayed on the visual as the axis,right?
Based on test, currently power bi desktop visuals not support this feature.
For your requirement, you can post it to idea.
https://ideas.powerbi.com/forums/265200-power-bi
Regards,
Xiaoxin Sheng
- singhal14Helper I
Hi Anonymous,
Thanks for Reaching out.
I am aware about that power bi does not support this feature.
But if we try it with using DAX funtions, may be we can achieve it.
I need your suggestions can we do it by using DAX Functions and if the answer is YES then what would be the approach?
Thanks,
Akash Singhal
- OwenAugerSuper User
Hi singhal14
Here's one idea of how it can be done using a bridging table.
Could well be other ways of handling this :)
- Assuming you have Region and Year lookup tables, create a RegionYear table which is the cross product of Region & Year tables.
- Duplicate each row of RegionYear and add an Axis Dimension column which is "Region" for half the rows and "Year" for the other half, and an Axis Value column which is the Region or Year value for each row (depending on the Axis Dimension value).
- Relate Year and Region to RegionYear using inactive bidirectional relationships:
- Create an Axis Dimension Selected measure to harvest the value of Axis Dimension. Something equivalent to this (this guards against multiple selection):
Axis Dimension Selected = IF ( ISFILTERED ( RegionYear[Axis Dimension] ), IF ( CALCULATE ( HASONEVALUE ( RegionYear[Axis Dimension] ), ALLSELECTED () ), VALUES ( RegionYear[Axis Dimension] ) ) ) - Create a Sales Amount Flexible Axis measure like this (assuming Sales Amount is the normal measure):
Sales Amount Flexible Axis = IF ( NOT ( ISBLANK ( [Axis Dimension Selected] ) ), SWITCH ( [Axis Dimension Selected], "Region",
CALCULATE ( [Sales Amount], USERELATIONSHIP ( RegionYear[Region], Region[Region] ) ), "Year",
CALCULATE (
[Sales Amount],
USERELATIONSHIP ( RegionYear[Year], 'Year'[Year] )
) )
) - Then you can create visualizations using RegionYear[Axis Value] and [Sales Amount Flexible Axis]
- haribPost Patron
It's was fine using card until user not select foucs mode.If the user click on focus mode card will disappear. :)
Thanks