Forum Discussion
Fixed Width column based on largest Label
Hello,
I am trying to reproduce this easy to build Tableau Chart in Power BI but it is harder than it looks:
The closest that I got is this using the Matrix visual:
The main pain points with this solution are:
1 - The width of columns are not the same as it depends on the lenght of the label for each year
2 - The lenght of the chart itself does not adjust to the max lenght of the visual. This creates a problem when I have many more years and creates an unecessary horizontal scroll bar.
Alternative options that I already tried include using a stacked bar chart (that fixed issue 2 as the bars adjusted to lenght of the visual card) and I used a fixed value 1 for the width of each year, but then no way to setup the colors based on the Grade column: here is how it looks:
Here is the sample that I used for this chart.
| Operation Number | Year | Grade |
| 123 | 2014 | ALERT |
| 123 | 2015 | PROBLEM |
| 123 | 2016 | PROBLEM |
| 123 | 2017 | PROBLEM |
| 123 | 2018 | PROBLEM |
| 123 | 2019 | ALERT |
| 123 | 2020 | PROBLEM |
If you have any ideas I would love to hear.
Thanks in advance
Rodrigo
Hi calloni
Matrix is the way ๐
According to the columns width,
to "freeze" them, you can apply these steps:
1. Create a measurerep = REPT("X",9)9 is the length of the longest string ("problem")+22. grab it to the values :3. switch the values to rows:
4. switch on auto size column width
5. 4. switch off auto size column width
6. remove rep measure
Result :
According to the responsivity of the matrix, you should plan the maximum width +/-, there are no other solutions
pbix is attached
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
2 Replies
- Ritaf1983Super User
Hi calloni
Matrix is the way ๐
According to the columns width,
to "freeze" them, you can apply these steps:
1. Create a measurerep = REPT("X",9)9 is the length of the longest string ("problem")+22. grab it to the values :3. switch the values to rows:
4. switch on auto size column width
5. 4. switch off auto size column width
6. remove rep measure
Result :
According to the responsivity of the matrix, you should plan the maximum width +/-, there are no other solutions
pbix is attached
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
- calloniHelper I
Thanks for the trick... I hope it is scalable for years to come (what will happen when a new year that wasn't fixed is added to the table?)
I guess I will have to wait and see ๐
Rodrigo