0

I am looking for some guidance on how to create a tracking table in Excel.

Today we receive a data dump with columns formatted below:

Vendor Agent Name Status Created Date Terminated Date VENDOR A AGENT 1 ACTIVE 05/14/2015 (blank) VENDOR A AGENT 2 INACTIVE 07/11/2019 08/10/2019 VENDOR A AGENT 3 ACTIVE 08/02/2019 (blank) VENDOR B AGENT 4 ACTIVE 06/15/2019 (blank) VENDOR B AGENT 5 ACTIVE 05/20/2019 (blank) VENDOR B AGENT 6 INACTIVE 05/17/2019 07/20/2019 VENDOR C AGENT 7 ACTIVE 08/05/2019 (blank) VENDOR C AGENT 8 INACTIVE 01/05/2018 08/20/2019

The statuses received will either be "ACTIVE" or "INACTIVE"

My idea is to have a pivot table showing the running count of active agents per vendor by week.

Vendor 07/01/2019 07/08/2019 07/15/2019 ... 08/05/2019 08/12/2019 ... 09/09/2019 VENDOR A 1 1 2 3 2 2 VENDOR B 2 2 2 2 2 3 VENDOR C 1 1 1 2 2 1

My issue is having the pivot table recognize the full active count for the particular week based on the status and 2 date columns.

Thanks for your time and any help you can provide!

2
  • 1
    I recommend using Excel Power Query/Get & Transform Data for this. You can consolidate/clean your data with Power Query and then load it to the data model so you can create a pivot table from it. You can refresh with additional data by simply clicking Data > Refresh. This should get you started support.office.com/en-us/article/… Commented Sep 11, 2019 at 17:22
  • Thanks @Jenn, while importing the data is not an issue, my trouble is with how to manage the data in a way to allow the pivot to provide the requested results. Does the data need to be stored in a certain way for me to be able to create the pivot in this way? My current resolution involves creating columns for each week and then creating flags identifying if active or not during that week. This now adds 52 columns to the data, but i was hoping for something a little more efficient. Commented Sep 11, 2019 at 19:51

2 Answers 2

1

It is possible to do this very easily with Power Query/Power Pivot which would be much more efficient and will not require you to create additional columns. If this is an ongoing project, saving each of the data dump files as a csv file will give you the best performance over time. You could also copy/paste the data into the same file for each refresh but that is up to you.

STEP 1 - Save the files in a folder.

For this example, I have created a file from your sample data as well as an additional file in the same format, to illustrate the process. I have saved the files in the same folder, with the file name as the date of the file 190915.csv and 190701.csv (2nd is just an example). Power Query will use the file name to add a file date column to the table as opposed to the user having to add a date column manually to each file.

Note - each file should have the same layout (column headers), the data should be on the first worksheet in the file and saved the same folder. The only other files that should be saved in this folder should be files to be consolidated in this process. Save other files somewhere else. (There are other options that work around this but doing it this way is easiest for beginners).

Sample File 1 Data Sample File 1 Data

Sample File 2 Data Sample File 2 Data

Snip of the files saved in a folder. Snip of the files saved in a folder

STEP 2 - Create a Date table.

We will create a date table, which we will relate to our data table. Open a new Excel file, or the file in which the pivot table should be created. This should not be one of your csv files. I have created a new Excel file (.xlsx) and saved it in the data files' parent folder.

Directory

In the Excel file, go to Data > New Query > From Other Sources > Blank Query

Add a Blank Query

The query editor window will appear with a blank query displayed. Click Advanced Editor on the toolbar to bring up the Advanced Editor. Copy the existing text and replace it with this code to add a new table of dates, beginning with 1/1/2020 and ending with today. Then click Done. Your will see the dates table in the query editor. In the Query Settings pane, rename your query to q_Dates. I also added a column for the start of each week. (From the ribbon > Add Column > Dates > Week > Start of Week)

Advanced Editor

let
    Source = #date(2010,1,1),
    GetListOfDatesThroughToday = List.Dates(Source, Number.From(DateTime.LocalNow())- Number.From(Source) ,#duration(1,0,0,0)),
    ConvertListToTable = Table.FromList(GetListOfDatesThroughToday, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    ChangeDataType = Table.TransformColumnTypes(ConvertListToTable,{{"Column1", type date}}),
    RenameCol1 = Table.RenameColumns(ChangeDataType,{{"Column1", "Date"}}) in
    RenameCol1

Rename Query

Dates Table

On the Ribbon, click Close and Load To. The query editor window will close and Excel will be displayed. A pop-up window will display. Choose Connection Only, check Load to Data Model and okay. This is telling Excel to load the data to the data model, we can related it to other data and not to create a new worksheet with the dates table.

Step 3 - Get the CSV data from our folder and make necessary edits (Get & Transform).

Back to the Ribbon, choose Data > New Query > From File > From Folder. Browse and select the folder in which your CSV files are saved and click okay. Now Excel will display your files that are in the folder. Click the down-carrot on Combine and choose Combine & Edit. You will then see a preview of the first data file. Just click okay.

enter image description here

The Query Editor Window will launch again and will navigate you to the query with the consolidated data. Instead, select query for the sample file and make your edits here. This tells Excel to make the same edits to all files in the folder.

enter image description here

Change the Created Date and Termination Date columns to date data types. Highlight the two columns and on the ribbon, choose Transform > Data type > Date.

Then go back down to the query that has the sheets consolidated and add a new column for the report date. (Ribbon > Add Column > Custom Column) Paste this in the formula window after the equals sign and click okay.

#date(Number.FromText(Text.Middle([Source.Name], 0, 2))+2000, Number.FromText(Text.Middle([Source.Name], 2, 2)), Number.FromText(Text.Middle([Source.Name], 4, 2)))

Now we are ready to add a new column to determine whether or not the agent was active as of the report date.

[Terminated Date] = null or [Terminated Date] > [Report Date] then "Active" else "Inactive"

Then Close and Load To (connection only, load to data model).

STEP 4 - Relate the Tables Using Power Pivot

From the Ribbon, go to Power Pivot > Manage. This is an add-in that you may need to enable.

Click here for more info if you do not see a Power Pivot tab on your ribbon. https://support.office.com/en-us/article/start-the-power-pivot-add-in-for-excel-a891a66d-36e3-43fc-81e8-fc4798f39ea8

The Power Pivot window will open and you will see one tab for each query/connection.

enter image description here

From the Power Pivot ribbon, go to Diagram View to see your connections as diagrams. Create a relationship between the dates table and your data table by clicking on the Date field of the Dates table and drag/drop onto the Report Date field in the Data table.

Pivot Relationship

Then from the ribbon, insert a pivot table and design as you would like. Relationships allow you to pull data from multiple tables into one pivot. Just save new files in the same folder and refresh.

Pivot

Sign up to request clarification or add additional context in comments.

Comments

0

As you also have the excel-formula appended, i will suggest a formula solution. For the list of vendors without doubles this formula would be useful: ARRAY-FORMULA: CTRL + SHIFT + ENTER

=IFERROR(INDEX(Tabelle1!$A$2:$A$21,MATCH(1,(COUNTIF(Tabelle1!$G$1:G1,A$2:A$21)=0)*(Tabelle1!A$2:A$21<>""),0)),"")

Apply this to cell G2. Take care with the ranges when adapting to your tables. The part $G$1:G1 has to be right above the first cell of this list and it must not contain entries from the list which you want to filter.

To count the number of active agents per vendor and week, this formula might be useful:

=SUMPRODUCT(($A$2:$A$9=$g2)*($C$2:$C$9="ACTIVE")*($D$2:$D$9<=H$1+7)*(($E$2:$E$9>H$1)+($E$2:$E$9="")))

Apply this to cell H1 and pull it downwards and sideways.

enter image description here

Does your result-table account for activity, as there can't be 3 active agents for VENDOR A in week 08/05/2019

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.