The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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 |
---|---|
28 | |
12 | |
8 | |
7 | |
5 |
User | Count |
---|---|
35 | |
14 | |
12 | |
9 | |
7 |