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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
MrBlackEyE31
Frequent Visitor

Combining Multiple Rows of data into one row.

Hello,

I have watched some videos and searched for some answers to my question, I have gotten close but haven't been able to get what I am trying to get. I have a table imported with multiple rows that looks somewhat similar to this



NumberTypeLocation
1PrimaryOrange - New York
1PrimarySyracus - New York
1SecondaryBuffalo - New York
1SecondaryRochester - New York
1SecondaryIthica - New York
2PrimaryBurlington - Vermont
2SecondaryStowe - Vermont
2SecondaryRutland - Vermont
2SecondaryBennington - Vermont


and I am looking to get this as a result

NumberPrimary LocationSecondary Location
1Orange - New York, Syracus - New YorkBuffalo - New York, Rochester - New York, Ithica - New York
2Burlington - VermontStowe - Vermont, Rutland - Vermont, Bennington - Vermont


Thank you for your time. 

1 ACCEPTED SOLUTION

Hi @MrBlackEyE31 

 

In @AnalyticPulse 's table, wrap the CONCATENATEX functions with CALCULATE.

 

CalculatedTable 2 = 
ADDCOLUMNS(
    SUMMARIZE(
        'Table',
        'Table'[Number]
    ),
    "Primary Location",
        CALCULATE(
            CONCATENATEX(
                FILTER(
                    'Table',
                    'Table'[Type] = "Primary"
                ),
                'Table'[Location],
                ", "
            )
        ),
    "Secondary Location",
        CALCULATE(
            CONCATENATEX(
                FILTER(
                    'Table',
                    'Table'[Type] = "Secondary"
                ),
                'Table'[Location],
                ", "
            )
        )
)

 

 

As an alternative, you could use @Arul 's measures like this.

 

CalculatedTable 3 = 
SUMMARIZE(
    'Table',
    'Table'[Number],
    "Primary",
        [Primary Location],
    "Secondary",
        [Secondary Location]
)

 

 

I would prefer the first option since it isn't really a best practice to use measures while defining calculated columns or calculated tables.

 

MrBlackEyE31.pbix

 



Proud to be a Super User!

daxformatter.com makes life EASIER!

View solution in original post

7 REPLIES 7
Arul
Super User
Super User

@MrBlackEyE31 ,

try these two measures,

Primary Location = CALCULATE(
    CONCATENATEX('Table','Table'[Location]),'Table'[Type] = "Primary")
Secondary Location = CALCULATE(
    CONCATENATEX('Table','Table'[Location]),'Table'[Type] = "Secondary")

Arul_0-1716395934690.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Thank you for your reply,  This gave me a column separating Primary locations and Secondary locations but did not combine them into 1 row. 

@MrBlackEyE31 ,

Do you need this?

Arul_0-1716402827487.png

 

Combine = CONCATENATEX('Table','Table'[Location])




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


AnalyticPulse
Super User
Super User

hello @MrBlackEyE31 
try this dax in calculated table;
CalculatedTable =
SELECTCOLUMNS(
SUMMARIZE('YourTable', 'YourTable'[Number]),
"Number", 'YourTable'[Number],
"Primary Location", CONCATENATEX(FILTER('YourTable', 'YourTable'[Type] = "Primary"), 'YourTable'[Location], ", "),
"Secondary Location", CONCATENATEX(FILTER('YourTable', 'YourTable'[Type] = "Secondary"), 'YourTable'[Location], ", ")
)

Learn Power BI free:

https://analyticpulse.blogspot.com

Learn Power BI free

Powerbi Visualisation

 

AnalyticPulse_0-1715829624787.png

 

Thank you for your help!

This is close, but it gave me back everything instead of the "Correct" options. 

I want it to look like this

NumberPrimary LocationSecondary Location
1Orange - New York, Syracus - New YorkBuffalo - New York, Rochester - New York, Ithica - New York
2Burlington - VermontStowe - Vermont, Rutland - Vermont, Bennington - Vermont


The solution you provided gave me something like this

NumberPrimary LocationSecondary Location
1Orange - New York, Syracus - New York, Burlington - VermontBuffalo - New York, Rochester - New York, Ithica - New York, Stowe - Vermont, Rutland - Vermont, Bennington - Vermont
2Orange - New York, Syracus - New York, Burlington - VermontBuffalo - New York, Rochester - New York, Ithica - New York, Stowe - Vermont, Rutland - Vermont, Bennington - Vermont


This is the closest I have come to getting what I want so you are on the right path here, Thank you!

Hi @MrBlackEyE31 

 

In @AnalyticPulse 's table, wrap the CONCATENATEX functions with CALCULATE.

 

CalculatedTable 2 = 
ADDCOLUMNS(
    SUMMARIZE(
        'Table',
        'Table'[Number]
    ),
    "Primary Location",
        CALCULATE(
            CONCATENATEX(
                FILTER(
                    'Table',
                    'Table'[Type] = "Primary"
                ),
                'Table'[Location],
                ", "
            )
        ),
    "Secondary Location",
        CALCULATE(
            CONCATENATEX(
                FILTER(
                    'Table',
                    'Table'[Type] = "Secondary"
                ),
                'Table'[Location],
                ", "
            )
        )
)

 

 

As an alternative, you could use @Arul 's measures like this.

 

CalculatedTable 3 = 
SUMMARIZE(
    'Table',
    'Table'[Number],
    "Primary",
        [Primary Location],
    "Secondary",
        [Secondary Location]
)

 

 

I would prefer the first option since it isn't really a best practice to use measures while defining calculated columns or calculated tables.

 

MrBlackEyE31.pbix

 



Proud to be a Super User!

daxformatter.com makes life EASIER!

Thank you for your response. This worked and did exactly what I wanted. Thanks again!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Kudoed Authors