This took me forever to figure out because it's so nuanced what has happened. You probably notice that when you remove the segment in the select cause for keyword, the data all adds up. I figured out why this is happening. You segmented by keyword. Some keywords come back while others don't. We know that all the keywords have impressions. However, the ones that do not come back have something in common; they are now removed keywords. So, the query is not returning keywords that are now removed even though on that day they had impressions.
Here are the next steps I'll take on this one. I've filed an issue with our query geniuses to ask if this is expected behavior. It seems odd, but I have a feeling I know why this may be happening. As you've seen, in the UI, there's no view like this where you can have the ads and the keywords nicely together. The UI doesn't have to account for that; you either see keywords with ad groups and campaigns or you see ads. I don't currently know of a workaround. I'll keep an eye on that internal issue to figure out if something can be done. I want to set expectations here that something as complicated as this may take a bit of time to figure out. I'll get back to you when I hear more. I'm really happy we have a 'why'; now we need to figure out the 'how' for how we're going to move forward.
Best,
Nadine Sundquist, Google Ads API Team
ref:_00D1U1174p._5001UHEPc7:ref