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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JulieB_
Helper I
Helper I

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 @JulieB_ 
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 @JulieB_ 
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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors