exceldatasheet

Adding 0 values to absent data in Excel


Over the past 20 years a bunch of wildlife counts have been conducted in a whole bunch of places across a country. When a species is detected, the amount of individuals is written down along with the location, year etc. If a species is not detected, it is not included in the count (not even as 0 of this species detected).

I have two datasheets. One with all the count data (i.e. how many of each species were seen at which location each year) and a sheet with where and when each count was conducted. I think to run any meaningful stats on this dataset I would need to add a 0 count to every year and location when a species wasn't detected when it had been detected at this location in different years.

For example if I had a dataset that ran from 2003-2008 and Species A was detected at Location B in 2004, 2005, 2006, and 2008, I would like to add a count of 0 for species A at Location B in 2003 and 2007.

Is there an automatic way to do this? My data set is about 34000 rows so doing this manually would probably take weeks and be prone to error.

Essentially I'm wondering if there is a way to take all the counts for each year/species/location combo and compare them to my datasheet detailing each year and location a count had taken place then for each location/year not found in the year/species/location combo add a row with the year/species/location and a count of 0. Ideally this would only be done for places where the species had been detected at some point over the 20 years of data. Some species will never be found in certain areas so it's unnecessary to include a count for these places for those species.

Any help would be appreciated.


Solution

  • This can be done without adding fake data. Set up a table for year, another table for location and one for species. Add these three dimension tables and the count table to the Excel data model.

    Create relationships between the count table and the dimension tables.

    enter image description here

    Then build a pivot table with the year, species and location from the dimension tables instead of the count table. In the pivot table options, on the Display tab, select to show items with no data on rows and columns. Now all the years, species and locations will show in the pivot table. If a combination does not have a count, it will show empty.

    enter image description here