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
Anonymous
Not applicable

CONCATENATEX does not work with GROUPBY

I have an invoice table which contains the columns "Client-ID", "Product" and "Price", amongst other columns. I'd like to group this table by client, with a second column "Product combination" that contains a concatenation of all the products per client. Initially, this is the code that I tried:

Clients = 
GROUPBY('Invoices'; 'Invoices'[Client-ID];
"Product combination"; 
CONCATENATEX(CURRENTGROUP(); 'Invoices'[Product code]))

When I use the code above, Power BI throws the error: "Function 'GROUPBY' scalar expressions have to be Aggregation functions over CurrentGroup(). The expression of each Aggregation has to be either a constant or directly reference the columns in CurrentGroup()." Which doesn't seem to make much sense, because I'm using CURRENTGROUP(), which 'Invoices'[Product code] is a part of.

I'm aware that I could use SUMMARIZE (which does work) instead of GROUPBY. Yet I intend to use the code above in a measure, with another GROUPBY to get the number of clients per product table. I have found that GROUPBY tends to be more accurate/intelligent when it comes to context filters, so I'd rather use GROUPBY (if possible). Could anybody tell me why this doesn't work and/or how to fix it? 🙂

2 ACCEPTED SOLUTIONS
Cmcmahan
Resident Rockstar
Resident Rockstar

So it looks like CURRENTGROUP simply does not work with CONCATENATEX.  Per the DAX documentation:

The CURRENTGROUP function takes no arguments and is only supported as the first argument to one of the following aggregation functions: AverageX, CountAX, CountX, GeoMeanX, MaxX, MinX, ProductX, StDevX.S, StDevX.P, SumX, VarX.S, VarX.P.

It is possible to do what you're attempting via Power Query, pretty easily:

https://stackoverflow.com/questions/44058355/powerquery-how-can-i-concatenate-grouped-values

 

Once you create the new table this way, you should be able to run measures against it as normal.

View solution in original post

Mariusz
Community Champion
Community Champion

Hi @Anonymous 

You can use the below DAX expression 

 

 

Table = 
ADDCOLUMNS(
    VALUES('Invoices'[Client-ID]);
    "Product combination";  CALCULATE( 
        CONCATENATEX( 
            VALUES( 'Invoices'[Product Code] );
            'Invoices'[Product Code]; "/ "
        ) 
    )
)


Regards,
Mariusz

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

2 REPLIES 2
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

You can use the below DAX expression 

 

 

Table = 
ADDCOLUMNS(
    VALUES('Invoices'[Client-ID]);
    "Product combination";  CALCULATE( 
        CONCATENATEX( 
            VALUES( 'Invoices'[Product Code] );
            'Invoices'[Product Code]; "/ "
        ) 
    )
)


Regards,
Mariusz

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

 

Cmcmahan
Resident Rockstar
Resident Rockstar

So it looks like CURRENTGROUP simply does not work with CONCATENATEX.  Per the DAX documentation:

The CURRENTGROUP function takes no arguments and is only supported as the first argument to one of the following aggregation functions: AverageX, CountAX, CountX, GeoMeanX, MaxX, MinX, ProductX, StDevX.S, StDevX.P, SumX, VarX.S, VarX.P.

It is possible to do what you're attempting via Power Query, pretty easily:

https://stackoverflow.com/questions/44058355/powerquery-how-can-i-concatenate-grouped-values

 

Once you create the new table this way, you should be able to run measures against it as normal.

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.