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
dw700d
Post Patron
Post Patron

create a new column that includes combined values of a grouping

I have  a location code, each location code consists of multiple location types. I would like to create a column in the query editor that identifies all the possible location types attributable to  a location code and combines it into one row. For example location Code A has 4 location types ( Mall,Store,House and Vendor) so any row where A is the location code I would see (Mall, Store,House,Vendor) in the proposed column.  Order is not important to me

 

 

Location Types
LOCATION CODELOCATION_TYPEProposed Column
AMallMall,Store,House,Vendor
AStoreMall,Store,House,Vendor
AHouseMall,Store,House,Vendor
AVendorMall,Store,House,Vendor
BMallMall,Hospital,School
BHospitalMall,Hospital,School
BSchoolMall,Hospital,School
CMallMall
DHouseHouse,School
DSchoolHouse,School
EVendorVendor,Mall,House
EVendorVendor,Mall,House
EMallVendor,Mall,House
EHouseVendor,Mall,House
LMallMall,Store
LMallMall,Store
LstoreMall,Store
LstoreMall,Store
LMallMall,Store
LMallMall,Store
LMallMall,Store
PstoreStore,house
PhouseStore,house
PhouseStore,house
PhouseStore,house

 

1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey @dw700d ,

 

if you want to use Power Query than you can use the following steps:
Starting with a table that looks like this:
image.png


Group the table using  Transform --> Group by:
image.png
The name of the new column is not that important, of course it will be used in subsequent steps.


Add a new custom column and use this formula:

//transforms the list values into a separated string by the given separator
Text.Combine(
    // removes duplicates from the list
    List.Distinct(
    // extracts the column values from the column LOCATION_TYPE     
    [GroupedValues][LOCATION_TYPE]
    ) , ","
)

The result should look like this:
image.png

 

Finally, you can expand the column GroupedValues.

 

Hopefully, this provides what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

3 REPLIES 3
CNENFRNL
Community Champion
Community Champion

CNENFRNL_1-1664993450686.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

TomMartens
Super User
Super User

Hey @dw700d ,

 

if you want to use Power Query than you can use the following steps:
Starting with a table that looks like this:
image.png


Group the table using  Transform --> Group by:
image.png
The name of the new column is not that important, of course it will be used in subsequent steps.


Add a new custom column and use this formula:

//transforms the list values into a separated string by the given separator
Text.Combine(
    // removes duplicates from the list
    List.Distinct(
    // extracts the column values from the column LOCATION_TYPE     
    [GroupedValues][LOCATION_TYPE]
    ) , ","
)

The result should look like this:
image.png

 

Finally, you can expand the column GroupedValues.

 

Hopefully, this provides what you are looking for.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
Jihwan_Kim
Super User
Super User

Hi,

In case if you want to create a new column by using DAX formula, please check the below.

 

Jihwan_Kim_0-1664988958647.png

 

 

New Column CC =
CONCATENATEX (
    SUMMARIZE (
        FILTER (
            'Location Types',
            'Location Types'[LOCATION CODE] = EARLIER ( 'Location Types'[LOCATION CODE] )
        ),
        'Location Types'[LOCATION_TYPE]
    ),
    'Location Types'[LOCATION_TYPE],
    ", "
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.