Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
Hello!
I have a matrix with the setting "values to rows" activated.
Since the column headers originally are values from a data column, the column headers change when I change the active filter. So does the width of the columns.
Is there any way to set a fixed column width? Nothing I have tried has worked.
Thanks in advance,
Moa
Hi @moaqvarnlof ,
To ensure consistent column widths dynamically in Power BI without manually adjusting them, you can use a DAX measure that pads the values or headers using the CONCATENATEX function. This method standardizes the length of the text displayed, which in turn helps Power BI render uniform column widths.
Start by creating a DAX measure that appends spaces to the values in your data. For example, you can write a measure like this:
PaddedValues =
CONCATENATEX(
VALUES('Table'[DataColumn]),
'Table'[DataColumn] & REPT(" ", 20 - LEN('Table'[DataColumn]))
)
This measure ensures that every value is padded to a fixed total length. Replace 20 with the desired length to suit your formatting requirements.
Next, if the column headers are also dynamic and causing the matrix to resize, create a similar calculated column for the headers:
PaddedHeaders =
CONCATENATEX(
VALUES('Table'[ColumnHeader]),
'Table'[ColumnHeader] & REPT(" ", 10 - LEN('Table'[ColumnHeader]))
)
This calculated column works in the same way by appending spaces to ensure a consistent header text length.
Power BI will render the matrix with consistent column widths because the padded text ensures that the visual space required remains constant. This approach eliminates the need for manual adjustments and provides a dynamic solution for managing uniform column widths effectively.
Best regards,
Thanks a lot for your answers!! Both @DataNinja777 and @KNP! Those are clever solutions to get the width to always stay the same! The problem I still have is that the column width that I need in my matrix is smaller than the length of the column header content. When I manually adjust to the needed column width, the content is divided into 2-3 lines of text inside the column header. This solution would work though if I did not need to narrow each column width down from its original width.
Hey @moaqvarnlof,
I have a solution that I think may be workable.
In power query (you could probably do this in DAX also as a calculated column), for the column you are using, you could replace spaces with a line feed #(lf) character.
= Table.ReplaceValue(fr1," ","#(lf)",Replacer.ReplaceText,{"CategoryName"})
The result is...
You could probably figure out a way to do every second or third word. I don't have time to do that at the moment.
I hope you can find a workable solution from this.
Have I solved your problem? Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;). |
If you found this post helpful, please give Kudos. It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen. If you find my signature vaguely amusing, please give Kudos. | Proud to be a Super User! |
I'm not sure I'm understanding your scenario fully.
This is what I thought you meant...
Have I solved your problem? Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;). |
If you found this post helpful, please give Kudos. It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen. If you find my signature vaguely amusing, please give Kudos. | Proud to be a Super User! |
Yes that's what I meant, but the problem is when something wider than "Music, Movies and Audio Books" takes place in the column. Then the column width increases to fit its content.
There must be something different about your scenario, because if I resize to the smallest and turn the setting off, I can't get it to do that.
Have I solved your problem? Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;). |
If you found this post helpful, please give Kudos. It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen. If you find my signature vaguely amusing, please give Kudos. | Proud to be a Super User! |
In my scenario, I have "Color Reference" under Columns in the matrix-settings, with "Values to rows" activated. Then, I filter out the top 15 values based in their corresponding sales, from the color column. This results in a matrix with 15 columns (black, red, pink, ..). There are a lot of different colors in "Color Reference", so when I change the date filter to another month for example, other colors might be in the top 15 when sorted by sales, and thereby the column headers change. When this happens, the column widths change even though I turn off the auto-size width.
Thanks for the reply from KNP , please allow me to provide another insight:
Hi, @moaqvarnlof
In my practical tests, prior to disabling the automatic width adjustment:
The row width is influenced by the size of your values and the text size of the column headers.
Once you disable this feature, the current column widths will be retained (please note that the widths of each column may not be consistent).
No matter how you adjust the font size or add filters, the widths will remain unaffected.
As for why your widths may have changed, I suspect it could be a version issue. I recommend upgrading your version to see if this resolves the problem.
Here is the download link:
Download Microsoft Power BI Desktop from Official Microsoft Download Center
If you wish for each column to maintain the same width, you might consider inserting a row (or column) in the visualisation as the longest column width.
Once you disable the automatic width adjustment, the sizes will remain fixed.
1.This is the original width:
2.After inserting the standard column and disabling the automatic width adjustment:
3.Replacing the value will not change the width either.
Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.
For questions about uploading data, you can try the following links:
How to provide sample data in the Power BI Forum - Microsoft Fabric Community
Solved: How to upload PBI in Community - Microsoft Fabric Community
Please find the attached pbix relevant to the case.
Of course, if you have any new discoveries or questions, please feel free to get in touch with us.
Best Regards,
Leroy Lu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks a lot for your response and ideas!!
I have the lastest Power BI Desktop version, so I don't think that's the issue..
The problem shows using your file aswell. Here, the column widths change if I instead choose the 3 colors with the lowest sales:
So if the content of the column header change, the width adapts to its new content.
I think I understand now.
@DataNinja777's idea caused me to test some more.
- If you create a simple measure
column_width = REPT("X", 40)
- Turn off any filtering to ensure all columns are showing.
- Turn ON 'Auto-size width'
- Drop measure into values.
- Turn OFF 'Auto-size width'
- Remove measure.
- Filter to test.
Have I solved your problem? Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;). |
If you found this post helpful, please give Kudos. It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen. If you find my signature vaguely amusing, please give Kudos. | Proud to be a Super User! |
Hi Moa,
If you select your matrix, go to formatting and search for "auto", you will get this...
Turn that setting off and it won't resize anymore.
Have I solved your problem? Please click Accept as Solution so I don't keep coming back to this post, oh yeah, others may find it useful also ;). |
If you found this post helpful, please give Kudos. It gives me a sense of instant gratification and, if you give me Kudos enough times, magical unicorns will appear on your screen. If you find my signature vaguely amusing, please give Kudos. | Proud to be a Super User! |
Thanks for you answer, but unfortunatly, that does not work. The column header content and its width still change when I filter the data..
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 |