Simple Power Query Pivot Question (I think!)

denzo36

Board Regular
Joined
Sep 22, 2019
Messages
221
Office Version
  1. 365
Platform
  1. Windows
Hi guys,

I'm pretty experienced with Excel but still a novice in Power Query so apologies in advance if this question is trivial for some but I can seem to find the solution anywhere.

I deal a lot with multiple policy numbers and which in turn can have multiple claim numbers. These are always listed in my data in rows, so each row will have a policy number and a claim number. For policies with multiple claims, each claim number is on a new row with the same policy number beside each claim. So for example, a policy with 4 claims will have 4 rows in my data, the same policy number on each row and the 4 different claim numbers listed on the row. The image may explain it better.

I'm trying to pivot this in some way so that I have one row for every policy number with the associated claim numbers pivoted in columns on the same row. I've tried pivot other columns etc but can't seem to get it to do what I want.

Could somebody steer me in the right direction?


Capture.PNG
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
try
PolicyClaimPolicyClaim.1Claim.2Claim.3Claim.4
P123456C11223344P123456C11223344C99887766C12365490C98765432
P123457C2114433P123457C2114433C5147821
P123458C55443322P123458C55443322C59871258
P123456C99887766
P123456C12365490
P123458C59871258
P123457C5147821
P123456C98765432

Code:
// Table1
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Group = Table.Group(Source, {"Policy"}, {{"CNT", each Table.RowCount(_), type number}, {"Count", each _, type table}}),
    List = Table.AddColumn(Group, "Claim", each [Count][Claim]),
    Extract = Table.TransformColumns(List, {"Claim", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    Split = Table.SplitColumn(Extract, "Claim", Splitter.SplitTextByAnyDelimiter({","}, QuoteStyle.Csv),List.Max(Group[CNT])),
    TSC = Table.SelectColumns(Split,{"Policy", "Claim.1", "Claim.2", "Claim.3", "Claim.4"})
in
    TSC
 
Upvote 0
Awesome, thanks works a treat, love the way Power Query allows you to check each step as well so I can work out what you did.

Much appreciated, cheers!
 
Upvote 0

Forum statistics

Threads
1,223,803
Messages
6,174,687
Members
452,577
Latest member
Filipzgela

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top