Forum Discussion
Combine and filter multiple Date/Time and data columns
This may or may not be compliated but I am new to power query and am still learning. I have a set of data that is a combination of 12 individual equiptment data columns, but each equiptment data has its own date/time column. The times do not always match and I cant just delete the other date/time columns. Also there is sometimes missing data or date/time values (It's one or the other missinbg not both). So I can't just append the tables together or else the date/time and correlating data may be wrong. How can I combine the columns into one and add another column that has the equipment line number. This may not be the best/optimized way to do it and am open to suggestions.
I tried searching and could not find something I could use. I found this forum/question that was similar except my data is the same for each date/time data combo.
I also only need 2 data points for every day at ~8AM and ~8PM. I am not sure if I should make a seperate post for this issue but thought I would add it here.
This is a snippet of the data I am working with. As you can see the times and days do not always match up on rows. I am using a filter right now to reduce the data points per day.
10 Replies
- KT_Bsmart2getheImpactful Individual
HI Anonymous ,
There are a few ways to achieve your desired outcome. First, consider you're new to Power Query and have your challenge resolved quickly. Could you provide sample data with sensitive information removed?
Then, I can provide step-to-step guidance on the solutions.
Regards
KT
- AnonymousNot applicable
So it seems my reply has dissapeared and wont let me reply to yours KT_Bsmart2gethe but here is a sample set of data. I want it to look something like this:
equipment 1: Date Time Part 1 Part 2 Part 3 Part 4 Part 5 equipment 2: Date Time Part 1 Part 2 Part 3 Part 4 Part 5 equipment 3: Date Time Part 1 Part 2 Part 3 Part 4 Part 5This is copy pasted from a csv file because I don't know how to attach a file here.
Part 1 Time,Part 1 Value,Part 2 Time,Part 2 Value,Part 2 Time,Part 3 Value 5/23/2022 14:18,0.138888881,5/23/2022 14:18,0.315789461,5/23/2022 14:18,0.118421048 5/23/2022 14:18,0.138888881,5/23/2022 14:18,0.315789461,5/23/2022 14:18,0.118421048 5/23/2022 14:18,0.138888881,5/23/2022 14:18,0.315789461,5/23/2022 14:18,0.118421048 5/23/2022 14:18,0.138522431,5/23/2022 14:18,0.315789461,5/23/2022 14:18,0.118421048 5/23/2022 14:18,0.138522431,5/23/2022 14:18,0.315789461,5/23/2022 14:18,0.118421048 5/23/2022 14:18,0.138522431,5/23/2022 14:18,0.315789461,5/23/2022 14:18,0.118421048 5/23/2022 14:18,0.138522431,5/23/2022 14:18,0.315789461,5/23/2022 14:18,0.118421048 5/23/2022 14:18,0.138522431,5/23/2022 14:18,0.315789461,5/23/2022 14:18,0.118421048 5/23/2022 14:18,0.138522431,5/23/2022 14:18,0.315789461,5/23/2022 14:18,0.118421048 5/23/2022 14:18,0.138522431,5/23/2022 14:18,0.315789461,5/23/2022 14:18,0.118421048 5/23/2022 14:18,0.138522431,5/23/2022 14:18,0.315789461,5/23/2022 14:18,0.118421048 5/23/2022 14:18,0.138522431,5/23/2022 14:18,0.315789461,5/23/2022 14:18,0.118110232 5/23/2022 14:19,0.138522431,5/23/2022 14:19,0.314960659,5/23/2022 14:19,0.118110232 5/23/2022 14:19,0.138522431,5/23/2022 14:19,0.314960659,5/23/2022 14:19,0.118110232 5/23/2022 14:19,0.138522431,5/23/2022 14:19,0.314960659,5/23/2022 14:19,0.118110232 5/23/2022 14:19,0.138157889,5/23/2022 14:19,0.314960659,5/23/2022 14:19,0.118110232 5/23/2022 14:19,0.138157889,5/23/2022 14:19,0.314960659,5/23/2022 14:19,0.118110232 5/23/2022 14:19,0.138157889,5/23/2022 14:19,0.314960659,5/23/2022 14:19,0.118110232 5/23/2022 14:19,0.138157889,5/23/2022 14:19,0.314960659,5/23/2022 14:19,0.118110232- KT_Bsmart2getheImpactful Individual
HI Anonymous,
Is below outcome what you're looking for?
I need to re-write part of the code to make it dynamic if this is what you are after.
Code:
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], //Only keep two Date/Time Columns KeepDateTime = Table.RemoveColumns( Source, List.RemoveFirstN( List.Select( Table.ColumnNames(Source), each Text.Contains(_,"Time") ), 2 ) ), //Renamed the two Date/Time columns to Date & Time RenamedDateTime = Table.RenameColumns( KeepDateTime, List.Transform( List.Select( Table.ColumnNames(KeepDateTime), each Text.Contains(_,"Time") ), each {_, if Text.StartsWith(_,"Part 2") then "Time" else "Date" } ) ), //Reordered columns to Date, Time, Part 1, 2 3 .... ReorderedCol = Table.ReorderColumns( RenamedDateTime, {"Date", "Time"} & List.Select( Table.ColumnNames(RenamedDateTime), each _<>"Time" and _<>"Date" ) ), //Changed Data Type Date & Time #"Changed Type" = Table.TransformColumnTypes( ReorderedCol, { {"Date", type date}, {"Time", type time} } ), //Demote headers before transpose DemotedHdrs = Table.DemoteHeaders(#"Changed Type"), //Transpose Table TransposedTbl = Table.Transpose(DemotedHdrs), //Add label - "Equipment x" (required to rewrite this part to make it dynamics label) CombineTbls = Table.Combine({#table({"Column1"},{{"Equipment 1:"}}),TransposedTbl}) in CombineTblsRegards
KT
- AnonymousNot applicable
This does look almost exactly what I need. If it is transposed that would be it.
- KT_Bsmart2getheImpactful Individual
Hi Anonymous ,
I have a few clarification questions:
- Is the data provided for equipment 1 / 2 /3?
- What is the expected value for the first screenshot?
I have a go with the provided data, and I have Part 1 Time that I then split into Date and Time, which returned Part 1 Date, Part 1 Time, Part 2 Date, Part 2 Time ....... So once you clarify the questions above, I'll provide you a step-by-step solution.
Regards
KT
- AnonymousNot applicable
The data provided is a small sample from 1 equipment. Once I can figure out 1 of them I can then apply it to the others.
The first screenshot shows that the times are not the same so it's not possible to just delete the extra date/time columns.
So I want to only have 1 date column and one time column per equipment. Each equipment has 8 parts and each part has its own set of Date/Time. You could make each part into its own table, but then you would have too many tables (20 equipment * 8 parts = 160 tables). So in my reply I tried giving an example of how I am trying to organize it.
1. Each equipment has its own table
2. Each table has 8 parts
3. Each table has 1 Date and 1 time column