How to count total items on the ground

Solution 1:

First you need a scoreboard to store the amount of items per entity into:

/scoreboard objectives add count dummy

Then you can easily transfer the stack size of every item entity into their "count" scoreboard like this:

/execute as @e[type=item] store result score @s count run data get entity @s Item.Count

If you want to do this only for a certain type of item, you can filter that as well:

/execute as @e[type=item,nbt={Item:{id:"minecraft:stone"}}] store result score @s count run data get entity @s Item.Count

Then you just need to add all those scores up to a shared score, for example yours:

/scoreboard players operation @s count += @e[type=item] count

Of course if you want to do this multiple times, you have to reset your score before the next repetition:

/scoreboard players reset @s count