looking for solution in Power Query

srehman

Board Regular
Joined
Jan 4, 2020
Messages
210
Office Version
  1. 2016
Platform
  1. Windows
Below is the table for cycle counts 1st , 2nd & 3rd according to time and date , but i want everything in one line , i need solution in power query please.

test2.xlsx
ABCDEFGHIJKL
1List IDPack ConfigLocationLocation ZoneSub ZoneHazmat IDBatch IDCount DateCount TimeExpectedCountedVariance
261956712X24X34AC03900A50PIC01LSS-SHOE21/05/2020 0:0012:10:41 PM32-1
361957012X24X34AC03900A50PIC01LSS-SHOE21/05/2020 0:0012:15:10 PM462
461956912X24X34AC03900A50PIC01LSS-SHOE21/05/2020 0:0012:12:54 PM242
Sheet1




test2.xlsx
ABCDEFGHIJKLMNOPQRSTUV
7Count1Count 2Count 3
8List IDPack ConfigLocationLocation ZoneSub ZoneHazmat IDBatch IDCount DateCount TimeExpectedCountedVarianceCount DateCount TimeExpectedCountedVarianceCount DateCount TimeExpectedCountedVariance
961956712X24X34AC03900A50PIC01LSS-SHOE21/05/2020 0:0012:10:41 PM32-121/05/2020 0:0012:15:10 PM46221/05/2020 0:0012:12:54 PM242
Sheet1
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hello,

One way is grouping on Pack Config, ...., Date. Using all rows as aggregate. I name this column often simply All.
Then use custom columns with the following formula structure: Table.Column([All], "Count Date") {0}, and repeat for Count Time, Expected, Counted and Variance.
To have 2nd and third from each list, replace {0} by {1}, {2}.
Formula for first List ID follows the same logic or you add a Min aggregate and select the column List ID.

Another faster way is repeating the same grouping, then using a Custom Column for each record: = [All] {0}, [All] {1}, [All] {2}. Finally extracting only those fields from the record you need in the final result.

Both are assuming there are always 3 records.
 
Upvote 0
Thanks for your support & time at this moment i cant understand your solution could my level is very low. I am trying .....
is there any one can you explain in more simple way if you can .......... sorry Even i tried not achieving.
 
Upvote 0
I thought to be rather explicit already. So here is the code. I hope this makes sense to you. If needed just ask me to explain a specific step in further detail. I can try that.
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Pack Config", "Location", "Location Zone", "Sub Zone", "Hazmat ID", "Batch ID"}, {{"ListID", each List.Min([List ID]), type number}, {"All", each _, type table [List ID=number, Pack Config=text, Location=text, Location Zone=text, Sub Zone=text, Hazmat ID=none, Batch ID=none, Count Date=datetime, Count Time=text, Expected=number, Counted=number, Variance=number]}}),
    ListIDAsFirstCol = Table.ReorderColumns(#"Grouped Rows",{"ListID", "Pack Config", "Location", "Location Zone", "Sub Zone", "Hazmat ID", "Batch ID", "All"}),
    GetFirst = Table.AddColumn(ListIDAsFirstCol, "First", each [All] {0}),
    GetSecond = Table.AddColumn(GetFirst, "Second", each [All]{1}),
    GetThird = Table.AddColumn(GetSecond, "Third", each [All]{2}),
    #"Expanded First" = Table.ExpandRecordColumn(GetThird, "First", {"Count Date", "Count Time", "Expected", "Counted", "Variance"}, {"Count Date.1", "Count Time", "Expected", "Counted", "Variance"}),
    #"Expanded Second" = Table.ExpandRecordColumn(#"Expanded First", "Second", {"Count Date", "Count Time", "Expected", "Counted", "Variance"}, {"Count Date.2", "Count Time.1", "Expected.1", "Counted.1", "Variance.1"}),
    #"Expanded Third" = Table.ExpandRecordColumn(#"Expanded Second", "Third", {"Count Date", "Count Time", "Expected", "Counted", "Variance"}, {"Count Date", "Count Time.2", "Expected.2", "Counted.2", "Variance.2"})
in
    #"Expanded Third"

On the UI:
1590057428745.png

Getting Records
1590057498732.png


Expanding
1590057562740.png

1590057540080.png
 
Upvote 0
Gr8 Thanks a lot its perfectly work now i have to implement same scenerio around 10000 lines and more column.

Now concept is more clear.

You are Champ.
 
Upvote 0
i just add few more lines i believe this query will work without any changes but i ma facing errors bc i have to implement this solutions around 10000 lines with different locations and List Ids
 
Upvote 0
Gr8 Thanks a lot its perfectly work now i have to implement same scenerio around 10000 lines and more column.

Now concept is more clear.

You are Champ.
You're welcome.
i just add few more lines i believe this query will work without any changes but i ma facing errors bc i have to implement this solutions around 10000 lines with different locations and List Ids
It all depends on how you need the grouping to appear, since you only had 1 scenario in your sample data, I could not foresee any potential hiccups. So try the solution on the full data set and see if you have code and or logical errors.
 
Upvote 0

Forum statistics

Threads
1,223,793
Messages
6,174,626
Members
452,575
Latest member
Fstick546

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