Quantcast
Channel: Desktop topics
Viewing all articles
Browse latest Browse all 216047

Creating a table from selected rows from another table

$
0
0

The data am I dealing with is about Staffing.  I need to show the number of open staffing requests over time, week by week.

 

We get staffing requests (identified by their Request ID) that get issued on Issued Date and closed on Closed Date.

 

We look at data at the week level. A week starting on Saturday and ending on Friday.

 

We consider that a staffing request was open on a given week if it was already issued by then (Issued Date <= Week Ending) and not closed yet (Closed Date > Week Ending).

 

I have a Staffing table that contains Request ID, Issued Date, and Closed Date:

Request ID

Open Date

Closed Date

1

2016-08-01

2016-08-02

2

2016-08-03

2016-08-07

3

2016-08-09

2017-01-02

4

2016-08-10

2017-01-03

5

2016-08-12

2016-08-14

6

2016-08-13

2016-08-28

7

2016-08-14

2016-08-17

8

2016-08-14

2017-01-03

 

What I need in the end is this:

Week Ending

Request ID

2016-08-05

2

2016-08-12

3

2016-08-12

4

2016-08-12

5

2016-08-19

3

2016-08-19

4

2016-08-19

6

2016-08-19

8

 Where for each week ending I list all Request IDs that were issued during that week but not yet closed.

 

I am able to get the list of Week Endings for the dataset with the following code (not sure if it is optimal but it works ;-) )

 

#"Added Week Ending"= Table.AddColumn(source, "Week Ending",                 each
//If Friday then we are on the week ending day                if Date.DayOfWeek([Date Issued])= 5                then Date.ToText([Date Issued],"d")                else
//If Saturday then next Friday is in 6 days                         if Date.DayOfWeek([Date Issued])= 6                then Date.ToText(Date.AddDays([Date Issued],6),"d")                else
//If Sunday then next Friday is in 5 days                         if Date.DayOfWeek([Date Issued])= 0                then Date.ToText(Date.AddDays([Date Issued],5),"d")                etc…
        ),

What I struggle with is looping through the data to get for each week the rows that meet the condition ([Date Issued] <= [Week Ending]) and ([Date Closed] > [Week Ending]))

 

I think I need to create a table with the list of week Endings (this I was able to).

Then another table where I add (using Table.FromRows or Table.FromList), week by week the rows from the source data that meet the criteria (using Table.SelectRows) but I don’t understand how to loop and how to reference other tables.

 

Maybe it’s not even the proper way to do it ;-)

 

Please help!


Viewing all articles
Browse latest Browse all 216047

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>