VBA Code to Assemble data horizontaly

%3CLINGO-SUB%20id%3D%22lingo-sub-1622193%22%20slang%3D%22en-US%22%3EVBA%20Code%20to%20Assemble%20data%20horizontaly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1622193%22%20slang%3D%22en-US%22%3E%3CP%3EHi%20All%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENeed%20help%20in%20Developing%20a%20vba%20code.%20I%20tried%20Power%20Query%20but%20could%20Pivot%20or%20Group%20using%20multiple%20filters.%3C%2FP%3E%3CP%3ECan%20somebody%20create%20a%20logic%20to%20compare%20data%20vertical%20to%20horizontal.%20I%20have%20attached%20my%20Excel%20for%20reference.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERaw%20Data%20Is%20the%20CVS%20Dump.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20assemble%20to%20Sample%20File.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20First%20and%20last%20event%20Vlookup%2C%20but%20i%20get%20results%20in%20different%20lines.%20Power%20Query%20i%20couldn't%20find%20a%20function%20which%20assemble%20like%20the%20sample%20data%20(which%20is%20the%20output%20file%20i%20need).%20Need%20help%20in%20resolving%20this%20issue.%20The%20current%20match%20up%20is%20purely%20done%20manually.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFilter%20required%20while%20setting%20up%20the%20raw%20data.%26nbsp%3B%3C%2FP%3E%3CP%3E%3CBR%20%2F%3EColumn%20F%3A%20Fault%20(Only%20include%20Moving%20Status)%3C%2FP%3E%3CP%3EColumn%20G%3A%20Fault%20Type%201%20(Stopped%20%26amp%3B%20moving)%20is%20the%20filter%20criteria.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1622193%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1622590%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Code%20to%20Assemble%20data%20horizontaly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1622590%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F735618%22%20target%3D%22_blank%22%3E%40Jeev125%3C%2FA%3E%26nbsp%3BDon't%20know%20what%20you%20tried%20in%20PQ%2C%20but%20I%20created%20something%2C%20based%20on%20the%20RawData%20that%20looks%20like%20your%20sample.%20See%20attached.%20Perhaps%20it%20helps.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1622684%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Code%20to%20Assemble%20data%20horizontaly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1622684%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%20Riny%2C%20i%20tried%20this%20solution%20before%20but%20my%20data%20has%20some%20notification%20without%20failure.%20what%20i%20am%20trying%20to%20match%20is%20if%26nbsp%3BDate%20%26amp%3B%20Time-Location-System-Equipment%20with%20moving%20status%20is%20STOPPED%20then%20same%20event%20should%20come%20with%20different%20time%20but%20with%20Moving.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20data%20is%20through%20a%20system%20generated%20so%20i%20have%20no%20control%2C%20I%20have%20attached%20Quarterly%20raw%20data%20wherein%20i%20have%203075%20line%20with%20moving%20status%20Stopped%20and%203196%20Moving.%20i%20want%20to%20match%20stop%20lines%20with%20moving%20and%20remove%20unmatched.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1622789%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Code%20to%20Assemble%20data%20horizontaly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1622789%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F735618%22%20target%3D%22_blank%22%3E%40Jeev125%3C%2FA%3E%26nbsp%3BDon't%20really%20know%20what%20I'm%20looking%20at.%20Can%20you%20explain%20in%20an%20example%20how%20you%20would%20match%20events%20and%20report%20them%20if%20you%20had%20to%20do%20it%20manually%2C%20using%20the%20data%20that%20you%20uploaded%20in%20your%20previous%20post%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1624098%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Code%20to%20Assemble%20data%20horizontaly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1624098%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3BThe%20logic%20whihc%20i%20used%20is%20First%20Stop%20and%20First%20Movingwhich%20ever%20is%20closest%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EExample%20%3A%20Stop%2012%3A30%3A00%26nbsp%3B%20%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMoving%2012%3A31%3A00%3C%2FP%3E%3CP%3EMoving%2012%3A32%3A00%3C%2FP%3E%3CP%3EMoving%2012%3A35%3A00%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20select%20the%20first%20Moving%2012%3A31%3A00.%20if%20Location-%20System-%20Equipment%20match.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20attached%20example.%3C%2FP%3E%3CP%3E1st%20Tab%20list-%20Events%20history%20with%20Filters%20thats%20the%20filter%20i%20use.%3C%2FP%3E%3CP%3E2nd%20Tab-%20Result%20which%20needs%20to%20be%20in%20this%20pattern.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20will%20be%20events%20which%20wont%20have%20both%20the%20events%20in%20that%20case%20we%20need%20to%20remove%20it.%20This%20were%20i%20am%20struggling%20in%20Power%20Query.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1624559%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Code%20to%20Assemble%20data%20horizontaly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1624559%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F735618%22%20target%3D%22_blank%22%3E%40Jeev125%3C%2FA%3E%26nbsp%3BChanged%20the%20approach%20altogether%20and%20didn't%20try%20to%20replicate%20your%20output.%20See%20if%20the%20attached%20PQ%20solution%20contains%20the%20logic%20you%20are%20after.%20Checked%20several%20events%20against%20the%20raw%20data.%20Seems%20to%20work%20OK%2C%20but%20you%20need%20to%20assure%20this%20yourself.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1629695%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Code%20to%20Assemble%20data%20horizontaly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1629695%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUsed%20your%20solution%20but%20when%20you%20use%20fill%20option%20some%20instance%20it%20copies%20date%20and%20time%20from%20other%20reference%20which%20is%20not%20matching%20to%20actual%20data.%20Now%20i%20need%20to%20get%20First%20occurrence%20and%20last%20occurrence%20of%20the%20same%20event%20to%20get%20exact%20match.%20Considering%20the%20logic%20Alarm%20as%20start%20%26amp%3B%20Normal%20as%20Finish.%20Any%20idea%20on%20that%20%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1629832%22%20slang%3D%22en-US%22%3ERe%3A%20VBA%20Code%20to%20Assemble%20data%20horizontaly%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1629832%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%20rel%3D%22noopener%22%3E%40Riny_van_Eekelen%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EAlso%20i%20tried%20using%20List.Max%20or%20List.First%20Function%20but%20i%20think%20it%20only%20take%20max%20or%20min%20values%20for%20the%20largest%20or%20smallest%20value.%20Somehow%20i%20must%20be%26nbsp%3B%20able%20to%20match%20Alarm%20time%20for%20that%20particular%20day%20location%20time%20to%20next%20Normal%20Date%20%26amp%3B%20time%20event%20only.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

Hi All,

 

Need help in Developing a vba code. I tried Power Query but could Pivot or Group using multiple filters.

Can somebody create a logic to compare data vertical to horizontal. I have attached my Excel for reference.

 

 

Raw Data Is the CVS Dump.

 

I want to assemble to Sample File.

 

I tried First and last event Vlookup, but i get results in different lines. Power Query i couldn't find a function which assemble like the sample data (which is the output file i need). Need help in resolving this issue. The current match up is purely done manually.

 

Filter required while setting up the raw data. 


Column F: Fault (Only include Moving Status)

Column G: Fault Type 1 (Stopped & moving) is the filter criteria.

 

 

7 Replies
Highlighted

@Jeev125 Don't know what you tried in PQ, but I created something, based on the RawData that looks like your sample. See attached. Perhaps it helps.

Highlighted

@Riny_van_Eekelen 

 

Hi Riny, i tried this solution before but my data has some notification without failure. what i am trying to match is if Date & Time-Location-System-Equipment with moving status is STOPPED then same event should come with different time but with Moving.

 

My data is through a system generated so i have no control, I have attached Quarterly raw data wherein i have 3075 line with moving status Stopped and 3196 Moving. i want to match stop lines with moving and remove unmatched. 

 

 

Highlighted

@Jeev125 Don't really know what I'm looking at. Can you explain in an example how you would match events and report them if you had to do it manually, using the data that you uploaded in your previous post?

Highlighted

@Riny_van_Eekelen The logic whihc i used is First Stop and First Movingwhich ever is closest

 

Example : Stop 12:30:00   

 

 

Moving 12:31:00

Moving 12:32:00

Moving 12:35:00

 

We select the first Moving 12:31:00. if Location- System- Equipment match.

 

I have attached example.

1st Tab list- Events history with Filters thats the filter i use.

2nd Tab- Result which needs to be in this pattern.

 

There will be events which wont have both the events in that case we need to remove it. This were i am struggling in Power Query. 

 

 

Highlighted

@Jeev125 Changed the approach altogether and didn't try to replicate your output. See if the attached PQ solution contains the logic you are after. Checked several events against the raw data. Seems to work OK, but you need to assure this yourself.

Highlighted

@Riny_van_Eekelen 

 

Used your solution but when you use fill option some instance it copies date and time from other reference which is not matching to actual data. Now i need to get First occurrence and last occurrence of the same event to get exact match. Considering the logic Alarm as start & Normal as Finish. Any idea on that ?

Highlighted

@Riny_van_Eekelen 

 

Also i tried using List.Max or List.First Function but i think it only take max or min values for the largest or smallest value. Somehow i must be  able to match Alarm time for that particular day location time to next Normal Date & time event only.