Forum Discussion
Dynamic change in X Axis
- 9 years ago
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]
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.
You're right uria! It would be more elegant to use Anonymous's method, like this example
Then there is no complexity in the DAX.
Since we have to combine Region and Year, would you imagine the data model looking something like this?
- harib7 years agoPost Patron
HI OwenAuger
It was nice idea, But when we select any value from Axis Dimension (Like Region), Region name should reflect in table Header instead of displaying the Axis value. can we achive this in Power BI. If yes kindly let me know.
Thanks in Advance
- OwenAuger7 years agoSuper User
harib can you clarify what you mean with a picture or other illustration?
- harib7 years agoPost Patron
What i mean to say . when we select Region or Year in slicer , it's reflecting in the table, it's fine , But Column title name is showing only Axis value. My requirment is if we select Region in slicer, Region name also should come on the column title and also same for year, if we select year , year name should reflect on the column title instead of displaying column name (Axis Value)
U have done good job. if you can find the answer of my question that's a great achivement.
Hope u understand.