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

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
gauravnarchal
Post Prodigy
Post Prodigy

Need help - Merging data based of Values

Hello All

 

I need your help in merging the data from multiple columns into one based on the values. Instead of creating a calculated column, I would like to create a new table.

 

I have attached the PBIX sample data for your kind assistance. Click Here

 

Condition

Of each InvoicedetailID  -        Find first SegmentID & First Leg Number and then Merge DepCityCode & ArrCityCode

& Of First SegmentID – find Second Leg Number and then Merge DepCityCode & ArrCityCode

& Of First SegmentID - find Third Leg Number and then Merge DepCityCode & ArrCityCode

& Of First SegmentID - find Fourth Leg Number and then Merge DepCityCode & ArrCityCode

                                                Continue……

 

While merging the data XO column is to be taken into consideration when merging.

 

All O values should be replaced with “*“

All X values should be replaced with “/“

 

And “-“ is to be used between DepCityCode and ArrCityCode in the final result.

 

The result column should merge the data and show as

For each InvoiceDetailsID - Segment column should show as  First DepCityCode-ArrCityCode(XO Condition)Second DepCityCode- Second ArrCityCode(XO Condition)Third DepCityCode & Third ArrCityCode…….....

 

Result Table is to be displayed as below.

 

InvoiceDetailIDSegment
2459255CAI-IST*IST-MAD
2459256DXB-DOH/DOH-IAH*IAH-DOH/DOH-DXB
2459260LHR-DXB*DXB-ATH
2459262ISU-DXB*DXB-EBL
2459395GLA-AMS/AMS-DXB*DXB-AMS/AMS-GLA

 

Thanks

Gaurav

1 ACCEPTED SOLUTION
richbenmintz
Resident Rockstar
Resident Rockstar

Hi @gauravnarchal ,

 

couple options:

1. create a calc column to concatente the results for each invoicedetailid

 

segments = 
var _idi = [InvoiceDetailID]
var _sep = ""
return
left(
    CONCATENATEX(FILTER('Sample', 'Sample'[InvoiceDetailID] = _idi) , 'Sample'[DepartureCityCode]&"-"&[ArrivalCityCode]&if([XO] = "X", "/","*"),"", [LegNumberTest Rank], ASC), 
    len(CONCATENATEX(FILTER('Sample', 'Sample'[InvoiceDetailID] = _idi) , 'Sample'[DepartureCityCode]&"-"&[ArrivalCityCode]&if([XO] = "X", "/","*"), "", [LegNumberTest Rank], ASC))
    -1
    )

 

2. create a calc table that summerizes the data at the invoice and invoicedetailid

 

group invoice details = 
SUMMARIZE('Sample',
'Sample'[InvoiceID],
'Sample'[InvoiceDetailID],
"segments", var _idi = [InvoiceDetailID]
var _sep = ""
return
left(
    CONCATENATEX(FILTER('Sample', 'Sample'[InvoiceDetailID] = _idi) , 'Sample'[DepartureCityCode]&"-"&[ArrivalCityCode]&if([XO] = "X", "/","*"),"", [LegNumberTest Rank], ASC), 
    len(CONCATENATEX(FILTER('Sample', 'Sample'[InvoiceDetailID] = _idi) , 'Sample'[DepartureCityCode]&"-"&[ArrivalCityCode]&if([XO] = "X", "/","*"), "", [LegNumberTest Rank], ASC))
    -1
    ))

 

richbenmintz_0-1627588737911.pngrichbenmintz_1-1627588757164.png

attached please find your sample with the formulas,

hope this helps,



I hope this helps,
Richard

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

Proud to be a Super User!


View solution in original post

1 REPLY 1
richbenmintz
Resident Rockstar
Resident Rockstar

Hi @gauravnarchal ,

 

couple options:

1. create a calc column to concatente the results for each invoicedetailid

 

segments = 
var _idi = [InvoiceDetailID]
var _sep = ""
return
left(
    CONCATENATEX(FILTER('Sample', 'Sample'[InvoiceDetailID] = _idi) , 'Sample'[DepartureCityCode]&"-"&[ArrivalCityCode]&if([XO] = "X", "/","*"),"", [LegNumberTest Rank], ASC), 
    len(CONCATENATEX(FILTER('Sample', 'Sample'[InvoiceDetailID] = _idi) , 'Sample'[DepartureCityCode]&"-"&[ArrivalCityCode]&if([XO] = "X", "/","*"), "", [LegNumberTest Rank], ASC))
    -1
    )

 

2. create a calc table that summerizes the data at the invoice and invoicedetailid

 

group invoice details = 
SUMMARIZE('Sample',
'Sample'[InvoiceID],
'Sample'[InvoiceDetailID],
"segments", var _idi = [InvoiceDetailID]
var _sep = ""
return
left(
    CONCATENATEX(FILTER('Sample', 'Sample'[InvoiceDetailID] = _idi) , 'Sample'[DepartureCityCode]&"-"&[ArrivalCityCode]&if([XO] = "X", "/","*"),"", [LegNumberTest Rank], ASC), 
    len(CONCATENATEX(FILTER('Sample', 'Sample'[InvoiceDetailID] = _idi) , 'Sample'[DepartureCityCode]&"-"&[ArrivalCityCode]&if([XO] = "X", "/","*"), "", [LegNumberTest Rank], ASC))
    -1
    ))

 

richbenmintz_0-1627588737911.pngrichbenmintz_1-1627588757164.png

attached please find your sample with the formulas,

hope this helps,



I hope this helps,
Richard

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

Proud to be a Super User!


Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.