Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredJoin us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.
Hi
I am trying to figure out what's the best way to subtract two rows in Power Query Editor:
I basically would like to do folllwing:
If Ref = RB and ObjectID of RB = ObjectID of L1 = Object ID of L2 then DateTime of L2 - DateTime of L1
I am trying to pick a correct path because I would need to also do something similar for RA scenario:
If Ref = RA and ObjectID of RA = ObjectID of L1 = Object ID of L2 then DateTime of L1 - DateTime of L2
Solved! Go to Solution.
Assuming your Object ID's are unique and always in groups of three, then the code below may get you started.
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Object ID", Int64.Type}, {"Ref", type text}, {"DateTime", type datetime}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Object ID"}, {
{"all", each _, type table [Object ID=nullable number, Ref=nullable text, DateTime=nullable datetime]},
{"RB Time Diff", (t)=>
if List.Contains(t[Ref],"RB")
then t[DateTime]{List.PositionOf(t[Ref],"L1")} -t[DateTime]{List.PositionOf(t[Ref],"L2")}
else null, type duration}
}),
#"Expanded all" = Table.ExpandTableColumn(#"Grouped Rows", "all", {"Ref", "DateTime"}, {"Ref", "DateTime"})
in
#"Expanded all"
They are always mean to be 3 records per set RB, L1 and L2 or AB, L1 and L2...
There are some outliers but removing them too.
So your suggestion is to do a custom column to do grouping? Can you please elaborate what that function/column could look like?
Assuming your Object ID's are unique and always in groups of three, then the code below may get you started.
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Object ID", Int64.Type}, {"Ref", type text}, {"DateTime", type datetime}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Object ID"}, {
{"all", each _, type table [Object ID=nullable number, Ref=nullable text, DateTime=nullable datetime]},
{"RB Time Diff", (t)=>
if List.Contains(t[Ref],"RB")
then t[DateTime]{List.PositionOf(t[Ref],"L1")} -t[DateTime]{List.PositionOf(t[Ref],"L2")}
else null, type duration}
}),
#"Expanded all" = Table.ExpandTableColumn(#"Grouped Rows", "all", {"Ref", "DateTime"}, {"Ref", "DateTime"})
in
#"Expanded all"
Need to know how to pick the relevant L1 and L2 for the given RB. If there will never be more than three identical Object ID's, you could group by Object ID's. Then check if you have an RB, L1 and L2 in each group and do your subtraction. If the refs should be broken up into groups of three, then you would create a custom column to do the grouping. If there is some other method to determine which L1 and L2 relate to a given RB, then you need to spell it out.
Once you decide how to determine which refs go together, you can write a custom aggregation to include the appropriate logic and output.
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.