简体   繁体   中英

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 (ie 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.

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.

在此处输入图片说明

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.

在此处输入图片说明

There might be a better solution to this but you can identify & replace the blank cells in a selected area using ' Go to ' function (shortcut: CTRL+G ) .

  1. You'll need to take a cell containing zero (0) and copy it.
  2. select the entire data block where you wish to replace blank cells with zeroes.
  3. Press CTRL+G > select ' Blanks ' > OK . This will highlight all Blank cells in the selected area.
  4. Then RIGHT CLICK on any one highlighted cell > Paste Special > Values (V) .

This would replace all the blanks with zeroes in your original sheet. You can then import this data wherever you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM