Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hi everyone,
I'm working on a DAX measure in Power BI that aims to format a string column ([name]) by inserting a line break (\n or UNICHAR(10)) every 14 characters without breaking words.
Here’s the current version of my measure:
nameindeneb =
VAR RawName = [name]
VAR CleanName = TRIM(RawName)
VAR Words = SUBSTITUTE(CleanName, " ", "|")
VAR WordCount =
IF(
NOT ISBLANK(Words),
PATHLENGTH(Words),
0
)
VAR WordList =
ADDCOLUMNS(
GENERATESERIES(1, WordCount),
"Word", PATHITEM(Words, [Value]),
"Length", LEN(PATHITEM(Words, [Value]))
)
VAR MaxChars = 15
VAR Result =
GENERATE(
WordList,
VAR Index = [Value]
VAR Word = [Word]
VAR PrevWords = FILTER(WordList, [Value] < Index)
VAR RunningLength =
SUMX(PrevWords, [Length] + 1) + [Length]
VAR Break = IF(RunningLength > MaxChars, UNICHAR(10), " ")
RETURN ROW("TextOut", Word & Break)
)
RETURN
IF(
WordCount = 0,
BLANK(),
CONCATENATEX(Result, [TextOut], "")
)However, this doesn’t produce the desired output. Instead of properly inserting line breaks to avoid going over the 14-character limit, it seems to add breaks inconsistently — often mid-line or too early/late. I suspect the logic around RunningLength and Break isn't tracking line lengths correctly as words accumulate.
Goal:
I want to format the [name] string such that:
Each line has at most 14 characters.
Words are never broken.
Words should wrap to the next line if they don’t fit on the current line.
Example Input:
I am cooking pasta for me and my wife
Expected output:
I am cooking
pasta for me
and my wife
Each line should not exceed 14 characters.
Thanks to anyone who will be able to pick this up!
Solved! Go to Solution.
Hi @Walter_Mangy please try this calculated column
Hi @Walter_Mangy please try this calculated column
@Walter_Mangy , Try using
DAX
nameindeneb =
VAR RawName = [name]
VAR CleanName = TRIM(RawName)
VAR Words = SUBSTITUTE(CleanName, " ", "|")
VAR WordCount =
IF(
NOT ISBLANK(Words),
PATHLENGTH(Words),
0
)
VAR WordList =
ADDCOLUMNS(
GENERATESERIES(1, WordCount),
"Word", PATHITEM(Words, [Value]),
"Length", LEN(PATHITEM(Words, [Value]))
)
VAR MaxChars = 14
VAR Result =
GENERATE(
WordList,
VAR Index = [Value]
VAR Word = [Word]
VAR PrevWords = FILTER(WordList, [Value] < Index)
VAR RunningLength =
SUMX(PrevWords, [Length] + 1) + [Length]
VAR Break = IF(RunningLength + [Length] > MaxChars, UNICHAR(10), " ")
RETURN ROW("TextOut", Word & Break)
)
RETURN
IF(
WordCount = 0,
BLANK(),
CONCATENATEX(Result, [TextOut], "")
)
Proud to be a Super User! |
|
Hi @bhanu_gautam thanks for picking this one up. Unfortunately your query doesn't seem like working. Did you try it on some specific text column? Thanks
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 21 | |
| 10 | |
| 9 | |
| 4 | |
| 4 |
| User | Count |
|---|---|
| 35 | |
| 31 | |
| 20 | |
| 13 | |
| 10 |