Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hi everyone, i have a problem with DAX syntaxt.
I would like to concatenate 2 columns into a new column but with a specific order. Let's make an example.
Suppose that we have into table A the columns: Names, Ages
Names | Ages |
Lucas, Walter, Marius Uan, Alex | 23,25,45,44 |
Debora | 21 |
I would like to calculate a new column called "Names and Ages" like that:
Lucas(23), Walter(25), Marius Uan(45), Alex(44)
Debora(21)
Could someone help me?
Thanks a lot in advice ❤️
Solved! Go to Solution.
@LordAssalt00 Try this:
Column =
VAR __NamesTable = SUBSTITUTE(SUBSTITUTE([Names], " ", ""),",", "|")
VAR __AgesTable = SUBSTITUTE(SUBSTITUTE([Ages], " ", ""),",", "|")
VAR __Length = PATHLENGTH(__NamesTable)
VAR __Table =
ADDCOLUMNS(
GENERATESERIES(1, __Length, 1),
"__Text", PATHITEM( __NamesTable, [Value]) & "(" & PATHITEM( __AgesTable, 1) & ")"
)
VAR __Result = CONCATENATEX( __Table, [__Text], ", " )
RETURN
__Result
@LordAssalt00 Try this:
Column =
VAR __NamesTable = SUBSTITUTE(SUBSTITUTE([Names], " ", ""),",", "|")
VAR __AgesTable = SUBSTITUTE(SUBSTITUTE([Ages], " ", ""),",", "|")
VAR __Length = PATHLENGTH(__NamesTable)
VAR __Table =
ADDCOLUMNS(
GENERATESERIES(1, __Length, 1),
"__Text", PATHITEM( __NamesTable, [Value]) & "(" & PATHITEM( __AgesTable, 1) & ")"
)
VAR __Result = CONCATENATEX( __Table, [__Text], ", " )
RETURN
__Result
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
11 | |
8 | |
7 |