Skip to content
Advertisement

Grouping Records by Key into a single row with multiple columns

I am struggling to get the data arranged how i would like. Essentially i am aiming to track a containers journey measuring time it spends in locations by looking a the times that it enters and leaves these locations

The table i am pulling from is pictured here #Extract Table containing Data

My code is below

And here is the output table Resultant Table

As you can see the data is each on its own row, I want to group by Container_FK so that each Entry has the whole journey

Many Thanks

Advertisement

Answer

Use aggregation:

Note that else null is redundant, so it is just wasted typing. Also, if Move_Indicator is a number, then remove the double quotes around the constants. Numbers should be compared to numbers, not strings.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement