Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Concatenate unique values of two columns with DAX measure

Hi there, 

 

I need to create a DAX measure that concatenates unique values of two columns in a text measure and sorts the values of the second column. 

See example below:

Column NAME and Text must we concatenated in a text measure.

I also want the Text column to be arranged from high to low values in the measure result.

 

Sample Table:

WeekNrNAMEMaterial KeyMaterialamountquantityText
31Expired Goods7630674food-5656,24-1032-5,656.2€ (-1032)  -> food (7630674)
31Expired Goods7331045clothes-5426,29-612-5,426.3€ (-612)  -> clothes (7331045)
31Expired Goods7581165ribs-2023,73-900-2,023.7€ (-900)  -> ribs (7581165)
31Expired Goods7329715shirt-2129,4-630-2,129.4€ (-630)  -> shirt (7329715)
31Push to7325844pants-7595,5-3744-7,595.5€ (-3744)  -> pants (7325844)

 

Desired DAX measure result:

Expired Goods:
-5,656.2€ (-1032) -> food (7630674),
-5,426.3€ (-612) -> clothes (7331045),

-2,129.4€ (-630) -> shirt (7329715)
-2,023.7€ (-900) -> ribs (7581165),
Push to:
-7,595.5€ (-3744) -> pants (7325844)

 

I tried this dax measure but it returns the wrong result:

 

VAR concattext = 
CALCULATE(
    CONCATENATEX(VALUES(WeeklyAnalysis[Text]), WeeklyAnalysis[Text], ", " & UNICHAR ( 10 )),
    RELATEDTABLE(WeeklyAnalysis)
)
VAR names = 
CALCULATE(
    CONCATENATEX(VALUES(WeeklyAnalysis[NAME]), WeeklyAnalysis[NAME] & concattext , ", " & UNICHAR ( 10 )),
    RELATEDTABLE(WeeklyAnalysis)
)
RETURN
names

 

It returns the wrong result: 

Scrap Expired Goods:
-5,656.2€ (-1032) -> food (7630674),
-5,426.3€ (-612) -> clothes (7331045),
-2,023.7€ (-900) -> ribs (7581165),
-2,129.4€ (-630) -> shirt (7329715),
-7,595.5€ (-3744) -> pants (7325844)
Push to:
-5,656.2€ (-1032) -> food (7630674),
-5,426.3€ (-612) -> clothes (7331045),
-2,023.7€ (-900) -> ribs (7581165),
-2,129.4€ (-630) -> shirt (7329715),
-7,595.5€ (-3744) -> pants (7325844)

 

Someone an idea? 

 

Kind regards,

Julie

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Anonymous 
Here is a sample file with the solutionhttps://www.dropbox.com/t/fhLtT0k3tEPToqGP

Result = 
CONCATENATEX (
    VALUES ( WeeklyAnalysis[NAME] ),
    WeeklyAnalysis[NAME] & UNICHAR ( 10 ) &
    CALCULATE (
        CONCATENATEX ( 
        WeeklyAnalysis,
        WeeklyAnalysis[Text], UNICHAR ( 10 ), WeeklyAnalysis[Text], DESC 
        )
    ), UNICHAR ( 10 ), WeeklyAnalysis[NAME], ASC 
)

View solution in original post

1 REPLY 1
tamerj1
Super User
Super User

Hi @Anonymous 
Here is a sample file with the solutionhttps://www.dropbox.com/t/fhLtT0k3tEPToqGP

Result = 
CONCATENATEX (
    VALUES ( WeeklyAnalysis[NAME] ),
    WeeklyAnalysis[NAME] & UNICHAR ( 10 ) &
    CALCULATE (
        CONCATENATEX ( 
        WeeklyAnalysis,
        WeeklyAnalysis[Text], UNICHAR ( 10 ), WeeklyAnalysis[Text], DESC 
        )
    ), UNICHAR ( 10 ), WeeklyAnalysis[NAME], ASC 
)

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.