Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

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.

 

NoahGrayhek_0-1658775232400.png

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 10
KT_Bsmart2gethe
Impactful Individual
Impactful 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

Anonymous
Not 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

Anonymous
Not 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 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.118110232

HI @Anonymous,

 

Is below outcome what you're looking for?

KT_Bsmart2gethe_0-1659436403256.png

 

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 

Anonymous
Not 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? 

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.

 

KT_Bsmart2gethe_0-1659535429875.png

 

I am sorry for asking too many questions, as I am clear about the outcome

 

Regards

KT

Anonymous
Not 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.

HI @Anonymous ,

 

I updated the code a bit. The key functions are Unpivot (All the Date Columns), GroupBy, Demote Headers and Transpose. I did remove duplicate rows (You can delete this step if it doesn't suit your situation. I did it because I found a lot of repetitive data which should be grouped IMO),

 

KT_Bsmart2gethe_0-1659567173198.png

 

Code:

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],

    //Replace missing data to 1/1/1900
    #"Replaced Value" = Table.ReplaceValue(
                            Source,
                            null,
                            #datetime(1900, 1, 1, 0, 0, 0),
                            Replacer.ReplaceValue,
                            List.Select(
                                Table.ColumnNames(Source), 
                                each 
                                    Text.Contains(_,"Time")
                            )
                        ),

    //
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(
                                #"Replaced Value", 
                                List.Select(
                                Table.ColumnNames(#"Replaced Value"), 
                                each 
                                    Text.Contains(_,"Value")
                            ), 
                                "TimeHdrs", 
                                "Date"
                            ),

    //Duplicate the date/time column
    #"Duplicated Column" = Table.DuplicateColumn(
                                #"Unpivoted Columns", 
                                "Date", 
                                "Time"
                            ),

    //Changed Type - Date and Time
    #"Changed Type" = Table.TransformColumnTypes(
                            #"Duplicated Column",
                            {
                                {"Date", type date}, 
                                {"Time", type time}
                            }
                        ),

    //Applied GroupBy - All Row to group Date and Time
    #"Grouped Rows" = Table.Group(
                            #"Changed Type", 
                            {"Date", "Time"}, 
                            {
                                {"Table", each _, type table}
                            }
                        ),

    //Expand all value columns (i.e. Part 1 Value, Part 2 Value ....
    #"Expanded Count" = Table.ExpandTableColumn(
                            #"Grouped Rows", 
                            "Table", 
                            List.Select(
                                Table.ColumnNames(#"Replaced Value"), 
                                each 
                                    Text.Contains(_,"Value")
                            )
                        ),

    //Removed replicate rows (This step can be removed)
    #"Removed Duplicates" = Table.Distinct(#"Expanded Count"),

    //Demote Headers before transposing to the desired view
    #"Demoted Headers" = Table.DemoteHeaders(#"Removed Duplicates"),

    //Transpose the table to the desired format
    #"Transposed Table" = Table.Transpose(#"Demoted Headers"),

    //Added Equipment# (This code needs to be updated with dynamic code. e.g. Equipment x. I need to understand how you pull the data, then I can update it.)
    AddedEquipmentx = #table({"Column1"}, {{"Equipment 1:"}}) & #"Transposed Table"
in
    AddedEquipmentx

 

Regards

KT

Anonymous
Not applicable

This does look almost exactly what I need. If it is transposed that would be it. 

KT_Bsmart2gethe
Impactful Individual
Impactful 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

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors