Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Modify table tricks needed

Hei,

 

I need some help with this table. For each Trip, I need to define its start and end time by:

Lets take a unique Trip number and when the second column is Loading, take the Depart time as the start of a trip and write it into a new column, when the second column is Discharing, take the Arrive time as the end of a trip and write it into a new column. If there are several rows of Loading for one Trip number, take the first of all Depart time and If there are several rows of Discharing for one Trip number, take the last of all Arrive time. I wish to have a table with only three columns, Trip number, Start time and end time of this trip. Can someone help me with this? Thanks in advance.

 

Trip numberReason for callDepartArrive
01901Loading1/23/2019 13:001/20/2019 11:10
01901Discharging2/10/2019 13:302/5/2019 0:01
01902Loading  
01902Loading5/4/2019 1:004/23/2019 16:00
01902Discharging5/15/2019 16:485/13/2019 8:36
01903Loading6/9/2019 8:066/5/2019 11:30
01903Discharging  
01903Discharging8/3/2019 8:348/2/2019 2:12
01904Loading8/22/2019 22:308/19/2019 3:36
01904Loading8/14/2019 16:358/12/2019 7:58
01904Loading  
01904Discharging10/7/2019 16:489/27/2019 21:00
01904Discharging  
01905Loading  
01905Loading12/20/2019 11:0012/16/2019 17:30
01905Discharging1/4/2020 9:001/2/2020 1:00
02001Loading1/12/2020 12:241/9/2020 19:30
02001Loading1/19/2020 21:001/18/2020 10:10
02001Discharging2/5/2020 17:002/1/2020 16:30
02001Discharging2/10/2020 12:122/6/2020 9:30
02001Discharging3/1/2020 3:002/11/2020 19:30
01901Loading8/23/2019 7:308/18/2019 18:06
01901Discharging9/8/2019 17:309/6/2019 8:06
01902Loading9/14/2019 12:489/8/2019 17:30
01902Discharging10/15/2019 9:1210/4/2019 16:48
01903Loading  
01903Loading10/27/2019 1:3010/21/2019 12:00
01903Discharging11/9/2019 21:4211/5/2019 21:30
01904Loading12/4/2019 19:3011/29/2019 7:30
01904Discharging12/19/2019 7:0012/14/2019 16:00
01905Loading1/5/2020 20:281/2/2020 10:00
01905Discharging  
01905Loading1/10/2020 10:001/6/2020 20:00
01905Discharging2/25/2020 13:482/9/2020 21:00
01905Discharging3/4/2020 16:002/27/2020 14:42

 

  • tex628's avatar
    tex628
    6 years ago

    Alright, give this a try:

    I begin with this table:


    Create a duplicate of this table, now we have Table 1 & Table 2. 


    In Table 1, filter reason for call on "Loading":


    In Table 1, highlight [Trip number] and [Unit Number] then press "Group By". Use the same setting as the picture below:


    Now we move onto Table 2. Filter the table on discharging then do anoth "Group By" with these settings:


    Finally we want to merge the two tables. Press "Merge as New" then use the following settings (Ctrl click to highlight more columns):


    Finally expand the "End" column:


    Should give you the following result, which i hope is correct:


    Br,
    J


     

  • tex628's avatar
    tex628
    6 years ago

    Happy to hear! I can actually help you out with that 😉

    Br,
    J

     

21 Replies

  • tex628's avatar
    tex628
    Community Champion

    Is this what you're looking for? 



    If that's the case i used these two calculated columns:

    Start = CALCULATE( MIN('Table (2)'[Depart]) ; ALL('Table (2)') ; 'Table (2)'[Reason for call] = "Loading" ; 'Table (2)'[Trip number] = EARLIER('Table (2)'[Trip number]))

     

    End = CALCULATE( MAX('Table (2)'[Arrive]) ; ALL('Table (2)') ; 'Table (2)'[Reason for call] = "Discharging" ; 'Table (2)'[Trip number] = EARLIER('Table (2)'[Trip number]))


    Br,
    J




    • Anonymous's avatar
      Anonymous
      Not applicable

      Hei, yes, this is almost what i want. I just need one row for a unique Trip number and remove the three columns in the middle...

       

      However, you syntax does not work on my pc. I changed my table name to Table (2), as I guess that is your table name and in Data - > Modelling -> Add a new column and put in your line into the formula area... but i got error message... is it becuase my dates have hierachy? but I cant remove it...

  • Anonymous 

    Try a new table like

     

     summarize(table, table[Trip number],"Depart",firstnonblank(Table[Depart],blank()),"Arrive",lastnonblank(Table[Arrive],blank()))
    or
    
     summarize(table, table[Trip number],"Depart",min(Table[Depart]),"Arrive",max(Table[Arrive]))