Counts over time for things that have a start date and end date

Hi, I work for a recruitment company where we have contractors working.  Does anyone know how I count the number of contractors out working over time when I have to take into account both a start and an end date?  Without this I am unable do do any trends for my senior management!

Many thanks

Zena

Best Answer

Answers

  • jaeW_at_Onyx
    jaeW_at_Onyx Budapest / Portland, OR 🟤

    Hey Zena, it's hard to address your question if we don't know how your data is currently structured (what's the granularity? can you provide a sample dataset?)  What are the metrics you want to sho in your trend report?

    If i had to guess you want to do something like the report "how many contractors were working on March 1 and your data is one row per contractor per contract and the start and end date of their engagement on that contract.  if that's the casse you need to JOIN the transactions to a date dimension using MySQL something like...

     

    select

    t.*

    d.date

    FROM

    contractor_transactions t

    INNER JOIN

    date d

    ON d.date between t.startDate and t.endDate

     

    make sure your contract strat and end dates are always populated or you'll exclude rows in your JOIN

     

     

    select

    t.*

    d.date

    FROM

    contractor_transactions t

    INNER JOIN

    date d

    ON d.date between t.startDate and coalesce(t.endDate, current_date)

     

  • Hi Jae, 

    Thanks for coming back to me, Your assumptions about how the data is structured are correct, but I've only used ETL and don't know SQL.  Is there anyway to achieve the same result using ETL? 

    Zena 

  • Magic ETL does not support non-equi JOINs so ... no.  The pseudo code I provided should work if you swap out table and field names.