How to match events in same line using Power Query

Occasional Contributor

I have a data set where i need match first Alarm and next Normal event into single line to find difference duration. i have attached a sample file with PQ uptill now. Need to get the output in one single line. 



Output should have 


Alarm Time & Normal Time in one line.

6 Replies

@Jeev125 You can Fill - Up column "Normal" and then filter out "null" from the "Alarm column". Furthermore, I'd recommend that you remove unwanted columns via the query, rather than hiding and deleting them from the table loaded into Excel.



Hi Riny, I cant use fill since the data is not consistent like Alarm & Normal. Also Fill copies UP or DN value to number of lines where my data doesn't follow the consistent patter.  Also condition with Raw Data i cant miss any line that the condition too.


I have attach Sample photo with the issue where i have t match colour coded cells respectively.




It looks like you need to merge the table with itself using Merged column, plus I think you don't need Date & Time column


Assuming I understand your need, the key to this problem is creating an ID to match Alarms and Normals to. For that we can use an Excel Formula. But before we add the formula, we should reduce the number of rows to just what we need. Oh, and to document things better I renamed Table1 to tblLift.


  1. I created a new query over tblLift that:
    • Selects only Fault entries for Lift Fault 
    • Selects only Equipment entries that begin with LFT-
    • Removes all other columns except Date & Time, Location, Equipment, Fault Type 1
    • Sorts rows by Equipment, Location, and Date & Time
  2. I loaded that back into Excel and with only the entries needed I added formulas to calculate an event ID. I:
    • Renamed the result table to tblFiltered
    • Added helper column Row=ROW()-ROW(tblFiltered[#Headers])
    • Added ID column which matches Equipment, Location, and Alarms to Normals 
        IF(INDEX([Equipment]&[Location], [@Row]-1)=[@Equipment]&[@Location],INDEX([ID],[@Row]-1), 0))+
        IF(TRIM([@[Fault Type 1]])="Alarm", 1, 0)

At this point we could just create a PivotTable but to keep things consistent I then created two more queries over tblFiltered

  1. The first is called Alarms that selects only Fault Type 1 entries with Alarm
  2. The second is called Normals selecting only Normal

Now I can join the two queries. So I created query Merge1 that:

  1. Inner Joins Alarms and Normals on Equipment, Location, and ID
  2. Expands Normals' Date & Time column
  3. Renames Alarms' Date & Time to Alarm and Normals' to Normal

I closed and loaded Merge1 into worksheet PQ Pivot. Below is the sample output. Hopefully that is on target with what you want. 


@Craig Hatmaker 

I am learning new every single day.

Hi Craig, your result is quite close but how do we capture this part where its an single event is there any way, check the attach snap.


Below snap is from Raw Data. Because the Equipment was at fault from 7th to 10th.Capture 11.png



@Jeev125 , 


Change the merge join type from Inner to LeftOuter


= Table.NestedJoin(Alarms,{"Location", "Equipment", "ID"},Normals,{"Location", "Equipment", "ID"},"Normals",JoinKind.LeftOuter)