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
Tooba_kazmi
Helper I
Helper I

How to merge rows with same headers having nulls, same as well as different datasets in rows?

Hi, 

I need help to merge multiple rows having same headers, nulls in some of the headers of multiple rows, having same data in some of the headers and different data in the other headers just as shown below:

 

Data in raw format:

Lead Created DateACTUAL_QUOTE_DTCONTRACT_STAGEPROCESSING_STATUSBRANCH_QUOTEDREFERRED_BYCUSTOMER_EMAILPRODUCTNET_PREMIUMPROCESSING_DT
null28-JulNew BusinessIncompletePB4nullrst@email.comLandlord$120028-Jul
null28-JulQuoteCompletePB4nullrst@email.comHome$100026-Aug
24-JulnullnullnullPB4xyz@email.comrst@email.comHomenullnull
24-JulnullnullnullPB4xyz@email.comrst@email.comLandlordnullnull

 

Desired Result:

Lead Created DateACTUAL_QUOTE_DTCONTRACT_STAGEPROCESSING_STATUSBRANCH_QUOTEDREFERRED_BYCUSTOMER_EMAILPRODUCTNET_PREMIUMPROCESSING_DT
24-Jul28-JulNew BusinessIncompletePB4xyz@email.comrst@email.comHome$100026-Aug
24-Jul28-JulQuoteCompletePB4xyz@email.comrst@email.comLandlord$120028-Jul

 

How can i get the desired result?

1 ACCEPTED SOLUTION

Hi @Tooba_kazmi,

You can enter to the 'query editor' to use group function to group these records based on "CUSTOMER_EMAIL","PRODUCT","BRANCH_QUOTED" fields. Then you can nest the ‘fill down’ function to process these records and filter not matched records to get merged result.

1.pngFull query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyivNyVHSUTKy0PUqBTH8UssVnEqLM/NSi4uBXM+85PzcgpzUklQgJ8DJBEhCdRQVlzik5iZm5ugBVQD5Pol5KTn5RSlApoqhkYEBwtBYHUxrAkvzwUY6E2m6R35uKthkA4jJZrqOpelgk41MoEZCdaJSEEMrKqtQTMNhOrJWahmNFCwoxscCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Lead Created Date" = _t, ACTUAL_QUOTE_DT = _t, CONTRACT_STAGE = _t, PROCESSING_STATUS = _t, BRANCH_QUOTED = _t, REFERRED_BY = _t, CUSTOMER_EMAIL = _t, PRODUCT = _t, NET_PREMIUM = _t, PROCESSING_DT = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Lead Created Date", type date}, {"ACTUAL_QUOTE_DT", type date}, {"CONTRACT_STAGE", type text}, {"PROCESSING_STATUS", type text}, {"BRANCH_QUOTED", type text}, {"REFERRED_BY", type text}, {"CUSTOMER_EMAIL", type text}, {"PRODUCT", type text}, {"NET_PREMIUM", Currency.Type}, {"PROCESSING_DT", type date}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","null",null,Replacer.ReplaceValue,{"Lead Created Date", "ACTUAL_QUOTE_DT", "CONTRACT_STAGE", "PROCESSING_STATUS", "BRANCH_QUOTED", "REFERRED_BY", "CUSTOMER_EMAIL", "PRODUCT", "NET_PREMIUM", "PROCESSING_DT"}),
    #"Grouped Rows" = Table.Group(#"Replaced Value", {"CUSTOMER_EMAIL","PRODUCT","BRANCH_QUOTED"}, {{"Content", each Table.Skip(Table.FillDown(_,Table.ColumnNames(_)),1), type table}}),
    #"Expanded Content" = Table.ExpandTableColumn(#"Grouped Rows", "Content", {"Lead Created Date", "ACTUAL_QUOTE_DT", "CONTRACT_STAGE", "PROCESSING_STATUS", "REFERRED_BY", "NET_PREMIUM", "PROCESSING_DT"}, {"Lead Created Date", "ACTUAL_QUOTE_DT", "CONTRACT_STAGE", "PROCESSING_STATUS", "REFERRED_BY", "NET_PREMIUM", "PROCESSING_DT"})
in
    #"Expanded Content"

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

6 REPLIES 6
Tooba_kazmi
Helper I
Helper I

Data in raw format:

Lead Created DateACTUAL_QUOTE_DTCONTRACT_STAGEPROCESSING_STATUSBRANCH_QUOTEDREFERRED_BYCUSTOMER_EMAILPRODUCTNET_PREMIUMPROCESSING_DT
null28-JulNew BusinessIncompletePB4nullrst@email.comLandlord$120028-Jul
null28-JulQuoteCompletePB4nullrst@email.comHome$100026-Aug
24-JulnullnullnullPB4xyz@email.comrst@email.comHomenullnull
24-JulnullnullnullPB4xyz@email.comrst@email.comLandlordnullnull

 

Desired Result:

Lead Created DateACTUAL_QUOTE_DTCONTRACT_STAGEPROCESSING_STATUSBRANCH_QUOTEDREFERRED_BYCUSTOMER_EMAILPRODUCTNET_PREMIUMPROCESSING_DT
24-Jul28-JulNew BusinessIncompletePB4xyz@email.comrst@email.comHome$100026-Aug
24-Jul28-JulQuoteCompletePB4xyz@email.comrst@email.comLandlord$120028-Jul

Hi @Tooba_kazmi,

You can enter to the 'query editor' to use group function to group these records based on "CUSTOMER_EMAIL","PRODUCT","BRANCH_QUOTED" fields. Then you can nest the ‘fill down’ function to process these records and filter not matched records to get merged result.

1.pngFull query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyivNyVHSUTKy0PUqBTH8UssVnEqLM/NSi4uBXM+85PzcgpzUklQgJ8DJBEhCdRQVlzik5iZm5ugBVQD5Pol5KTn5RSlApoqhkYEBwtBYHUxrAkvzwUY6E2m6R35uKthkA4jJZrqOpelgk41MoEZCdaJSEEMrKqtQTMNhOrJWahmNFCwoxscCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Lead Created Date" = _t, ACTUAL_QUOTE_DT = _t, CONTRACT_STAGE = _t, PROCESSING_STATUS = _t, BRANCH_QUOTED = _t, REFERRED_BY = _t, CUSTOMER_EMAIL = _t, PRODUCT = _t, NET_PREMIUM = _t, PROCESSING_DT = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Lead Created Date", type date}, {"ACTUAL_QUOTE_DT", type date}, {"CONTRACT_STAGE", type text}, {"PROCESSING_STATUS", type text}, {"BRANCH_QUOTED", type text}, {"REFERRED_BY", type text}, {"CUSTOMER_EMAIL", type text}, {"PRODUCT", type text}, {"NET_PREMIUM", Currency.Type}, {"PROCESSING_DT", type date}}),
    #"Replaced Value" = Table.ReplaceValue(#"Changed Type","null",null,Replacer.ReplaceValue,{"Lead Created Date", "ACTUAL_QUOTE_DT", "CONTRACT_STAGE", "PROCESSING_STATUS", "BRANCH_QUOTED", "REFERRED_BY", "CUSTOMER_EMAIL", "PRODUCT", "NET_PREMIUM", "PROCESSING_DT"}),
    #"Grouped Rows" = Table.Group(#"Replaced Value", {"CUSTOMER_EMAIL","PRODUCT","BRANCH_QUOTED"}, {{"Content", each Table.Skip(Table.FillDown(_,Table.ColumnNames(_)),1), type table}}),
    #"Expanded Content" = Table.ExpandTableColumn(#"Grouped Rows", "Content", {"Lead Created Date", "ACTUAL_QUOTE_DT", "CONTRACT_STAGE", "PROCESSING_STATUS", "REFERRED_BY", "NET_PREMIUM", "PROCESSING_DT"}, {"Lead Created Date", "ACTUAL_QUOTE_DT", "CONTRACT_STAGE", "PROCESSING_STATUS", "REFERRED_BY", "NET_PREMIUM", "PROCESSING_DT"})
in
    #"Expanded Content"

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

This works perfectly fine for small data set but not with large. 

Can you please explain this in a step by step process to make it clear for me?

Ashish_Mathur
Super User
Super User

Hi,

Your data has not been pasted properly.  Share data in a format that can be pasted in an MS Excel file and show the expected result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
amitchandak
Super User
Super User

@Tooba_kazmi , You can use group by with min/max and count options

 

https://docs.microsoft.com/en-us/power-query/group-by

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.