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
Moulahoum
New Member

Concatenate text by group : EARLIER function not working

Hello everyone,

 

I am trying to create a measure in DAX to concatenate all CODES that have the same Group ID.

I have tried the CONCATENATEX function mentioned in many other discussion threads but it doesn't seem to function as there appears to be a problem with the function EARLIER which doesn't recognize any value.

This is the initial table:

Group Registration IDSPN CODE
578-24-3545895SM-CC
578-24-3545895WR-SF
578-24-3544933FU-TR
578-24-3544933SM-AD
578-24-3544933SM-CC
578-24-3544933WR-SF
578-24-3532081WR-SF
578-24-3524650SM-DP
578-24-3518403LP-MS
578-24-3518403N/A

The desired output should be as such:

578-24-3545895SM-CCSM-CC; WR-SF
578-24-3544933FU-TRFU-TR; SM-AD; SM-CC; WR-SF
578-24-3532081WR-SFWR-SF
578-24-3524650SM-DPSM-DP
578-24-3518403LP-MSLP-MS; N/A

I have tried this but it's not working and I have the following error :

CODES = CONCATENATEX(FILTER(SPN, SPN[Group Registration ID]=EARLIER(SPN[Group Registration ID])), SPN[SPN CODE], "; ")

Moulahoum_0-1709640767170.png

 

I would appreciate any orientation

 

Thank you

2 ACCEPTED SOLUTIONS
HotChilli
Super User
Super User

If you are writing a measure, it will be a bit simpler than the code shown.

Follow the example here https://learn.microsoft.com/en-us/dax/concatenatex-function-dax?WT.mc_id=DP-MVP-4025372#example 

View solution in original post

v-heq-msft
Community Support
Community Support

Hi @Moulahoum ,
@JamesFR06 Good solution.
Here's what I need to add
According to mine using your data to test the dax you wrote in power bi, when I put your dax code into measure, he got the same error as you. But when you use the calculated columns, your dax code runs with the results you want. According to the documentation I checked, EARLIER succeeds if there is a row context prior to the beginning of the table scan. otherwise it returns an error.

vheqmsft_0-1709705513727.png

vheqmsft_1-1709705559030.png

Also, you can create a new table

Table = 
ADDCOLUMNS(
    SUMMARIZE('SPN', 'SPN'[Group Registration ID]),
    "Codes", 
    CONCATENATEX(
        FILTER('SPN', 'SPN'[Group Registration ID] = EARLIER('SPN'[Group Registration ID])),
        'SPN'[SPN CODE],
        "; "
    )
)

Final output

vheqmsft_2-1709705616588.png


EARLIER function (DAX) - DAX | Microsoft Learn

Best regards,

Albert He

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

4 REPLIES 4
v-heq-msft
Community Support
Community Support

Hi @Moulahoum ,
@JamesFR06 Good solution.
Here's what I need to add
According to mine using your data to test the dax you wrote in power bi, when I put your dax code into measure, he got the same error as you. But when you use the calculated columns, your dax code runs with the results you want. According to the documentation I checked, EARLIER succeeds if there is a row context prior to the beginning of the table scan. otherwise it returns an error.

vheqmsft_0-1709705513727.png

vheqmsft_1-1709705559030.png

Also, you can create a new table

Table = 
ADDCOLUMNS(
    SUMMARIZE('SPN', 'SPN'[Group Registration ID]),
    "Codes", 
    CONCATENATEX(
        FILTER('SPN', 'SPN'[Group Registration ID] = EARLIER('SPN'[Group Registration ID])),
        'SPN'[SPN CODE],
        "; "
    )
)

Final output

vheqmsft_2-1709705616588.png


EARLIER function (DAX) - DAX | Microsoft Learn

Best regards,

Albert He

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

JamesFR06
Resolver IV
Resolver IV

Please find the measure :

Mesure 2 =
var Groupe=SELECTEDVALUE(Concat[Group Registration ID])
var result=CONCATENATEX(filter(Concat,Concat[Group Registration ID]=groupe),Concat[SPN CODE],",")
return
result
JamesFR06_0-1709657556136.png

 

HotChilli
Super User
Super User

If you are writing a measure, it will be a bit simpler than the code shown.

Follow the example here https://learn.microsoft.com/en-us/dax/concatenatex-function-dax?WT.mc_id=DP-MVP-4025372#example 

This is the simplest function that solvedit. Thank you.

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.