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
gauravnarchal
Post Prodigy
Post Prodigy

Need help in creating new table and 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
lbendlin
Super User
Super User

Create a helper column

 

XO2 = 'Sample'[DepartureCityCode] & "-" & 'Sample'[ArrivalCityCode] & switch('Sample'[XO],"X","/","*")

 

Then create the segment column

 

Segment = 
var t = CALCULATETable('Sample',ALLEXCEPT('Sample','Sample'[InvoiceDetailID]))
var l=CONCATENATEX(t,[XO2],"",[SegmentID])
return left(l,LEN(l)-1)

 

lbendlin_1-1627672990604.png

You removed the Leg Number from your source data so maybe it cannot be sorted correctly?

 

"Instead of creating a calculated column, I would like to create a new table." - Sure, but why?

 

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

Create a helper column

 

XO2 = 'Sample'[DepartureCityCode] & "-" & 'Sample'[ArrivalCityCode] & switch('Sample'[XO],"X","/","*")

 

Then create the segment column

 

Segment = 
var t = CALCULATETable('Sample',ALLEXCEPT('Sample','Sample'[InvoiceDetailID]))
var l=CONCATENATEX(t,[XO2],"",[SegmentID])
return left(l,LEN(l)-1)

 

lbendlin_1-1627672990604.png

You removed the Leg Number from your source data so maybe it cannot be sorted correctly?

 

"Instead of creating a calculated column, I would like to create a new table." - Sure, but why?

 

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.

Top Solution Authors