Forum Discussion
Combine and filter multiple Date/Time and data columns
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 5
This 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.118110232HI 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
CombineTbls
Regards
KT
- Anonymous4 years agoNot applicable
This does look almost exactly what I need. If it is transposed that would be it.
- Anonymous4 years agoNot applicable
So I went through your code and I see it just deletes the dates of the other columns but it can't just do that. It needs to check and make sure the dates and times match or are at least close to each other. The screen shot in the original post showed the need for it. Some can have blank data or not recorded anything for a full day.
I am not versed I. DAX but would it be best to to write code to check if the times match and if not then match it to the correct date+time?
- KT_Bsmart2gethe4 years ago
Impactful Individual
Hi Anonymous
I just went through the original post. Somehow, I missed it.
I am not sure if I fully understood the date logic. For example, what should we do if there is a missing date or unmatch date? I need to understand to be able to write the code.
I was wondering if grouping the date is an option.
I am sorry for asking too many questions, as I am clear about the outcome
Regards
KT
- Anonymous4 years agoNot applicable
So if the dates do not match they should be moved/grouped with the proper time so they match. If the data is missing for a certain time then it should just be left blank or 0. The tolerance is not firm. So if the time is 5 seconds off then it can be grouped together. Maybe it can be run through a filter so that the average, max, and min of 5 seconds is returned. There is a few ways that each one could be needed (sometimes need the max, other times the average is needed. This would be changed later depending on the particular need). This issue is a common one that prevents moving forward on a few different things.
If times match then its good if not then put 0 in value for that part.