help in Building a query in AX 2012

Hi, I am new to AX. I have a case where there are multiple projects(p1, p2 p3…). With each project there are multiple jobs/operations(p1-(job1, 2, 3), p2(Job4, 5), p3(Job8, Job9, Job10). Also, there is a case where same operations with varying quantities are repeating on different days (p3(job8 – transdate1, job8-transdate2), p3(job9- transdate3, job9- transdate4), p3(job10- transdate5). If the same operation is repeating I want to get the latest transdate(job8, transdate2) and substract it from earliest subsequent job(job9, transdate3) and display the no. of bench days(i = job9(transdate3) – job8(transdate2)) between two operations excluding the weekends. Can anyone help me with the logic?

I am not sure it is prudent to try to build such a query as you are introducing business logic complexities at the same time. If data needs to be handled by varying business logic then you can opt for building a query to get the data and store the calculated results in a temp table. Display then temp table on the form. Other way around it would be to display the bulk of the data through a simple query and leave the calculations to display methods that can then calculate bench days.