Forum Discussion
Concatenate 2 text measures without duplicates
- 5 years ago
One approach would be to use "|" instead of ", " as a separator, and then work with the PATHITEM() function in DAX.
Another approach would be to convert your text string into a table variable.
By the way, your table 1 is not required, and neither is your TAGS2 measure. Unless your sample data is not representative?
CALCULATED COLUMN TAGS2:
TAGS2 = SUBSTITUTE('Table 2'[Tags Table 2],", ","|")Measures:
TAGS3 = CONCATENATEX(values('Table 3'[Tags Table 3]),'Table 3'[Tags Table 3],",") Measure = var t3=SUMMARIZE(ADDCOLUMNS(values('Table 3'[Tags Table 3]),"TAG",'Table 3'[Tags Table 3]),[TAG]) var u=UNION(t3,row("TAG",PATHITEM(SELECTEDVALUE('Table 2'[TAGS2]),1)),row("TAG",PATHITEM(SELECTEDVALUE('Table 2'[TAGS2]),2))) return CONCATENATEX(DISTINCT(FILTER(u,[TAG]<>BLANK())),[TAG],",")Note: this is just for illustration - you need to union the other path rows too if there are more than two.
Result:
Note the data quality issues around SILK and the empty string for XXXX4 (I replaced that with null in the data load).
One approach would be to use "|" instead of ", " as a separator, and then work with the PATHITEM() function in DAX.
Another approach would be to convert your text string into a table variable.
By the way, your table 1 is not required, and neither is your TAGS2 measure. Unless your sample data is not representative?
CALCULATED COLUMN TAGS2:
TAGS2 = SUBSTITUTE('Table 2'[Tags Table 2],", ","|")
Measures:
TAGS3 = CONCATENATEX(values('Table 3'[Tags Table 3]),'Table 3'[Tags Table 3],",")
Measure =
var t3=SUMMARIZE(ADDCOLUMNS(values('Table 3'[Tags Table 3]),"TAG",'Table 3'[Tags Table 3]),[TAG])
var u=UNION(t3,row("TAG",PATHITEM(SELECTEDVALUE('Table 2'[TAGS2]),1)),row("TAG",PATHITEM(SELECTEDVALUE('Table 2'[TAGS2]),2)))
return CONCATENATEX(DISTINCT(FILTER(u,[TAG]<>BLANK())),[TAG],",")
Note: this is just for illustration - you need to union the other path rows too if there are more than two.
Result:
Note the data quality issues around SILK and the empty string for XXXX4 (I replaced that with null in the data load).