Guidance for newbie on summarizing data in Calc: pivot table or custom macros?

I am a newbie to Calc but I do have experience with VBA, albeit specific to MS Access only. I don’t have much experience with Excel either. Anyways, I am looking to avoid going down a blind alley if there is an obvious solution to my problem.

I am using Calc to track my nutrition. I have created 3 sheets in a Calc document. The first tracks data for foodstuffs, like so:

Note the units of measurement are grams/ounce.

The second is where I log what I eat, with the date, foodstuff and amount in ounces. I have already set it such that I can only enter foodstuffs that have a corresponding entry in the first sheet:

Day Food Amount
08/29/21 Oats 1.5
08/29/21 Yogurt 3.5
08/29/21 Peach 5.3
08/29/21 Ham 1
08/30/21 Milk 8

Now, I want a third sheet that summarizes the calories, proteins, etc by date. The way I would imagine doing this would be to loop through every row in sheet 2, then look up the nutritional info for the foodstuff within sheet #1 ,and then calculate the total calories,fat,protein, and carbs for that row.

For example, if I ate 3.5 oz of Yogurt on 8/29/21, that would be 3.5g protein, 4.9g carbs, 3.5g fat, and 65.1 calories. Now, I do this for every row and then aggregate by date, such that the third sheet has rows headers like so:

Calculated Totals
Date Calories Protein Fat Carbs

To sum up, I see the following that tasks that need to be automated:

(1) look up foodstuff
(2) calculate nutrition per amount of foodstuff
(3) aggregate calculations per day (or week, month…)

According to my research, (3) is a good candidate for a a pivot table but considering the other tasks and the fact that I don’t particularly need the intermediate numbers this could conceivably be accomplished through LibreOffice Basic functions doing everything behind the scenes. On the other hand, it wouldn’t hurt anything to have the intermediate numbers visible either, if this be done completely by chaining built in commands.

I’d like it be done automatically whenever sheet #2 gets a new row.

I have discovered the Pitonyak book on macros, and I am going through it even although OOo 3.x appears to be somewhat divergent from my platform (LibreOffice 7.0.4).

What is the best way forward?

In Sheet 2 you need calculated Columns for Protein, Carbs, etc.

=VLOOKUP( food ; $Sheet1.$A$3:$E$???; the correspodenting Column-number ; 0 )  * amount

The Rest is easy by Pivot Table from Source in Sheet2:
‘Day’ pulled to Row-Field.
‘Protein’, ‘Carbs’, ‘Fat’, ‘Calories’ pulled into Data-field, all with the default SUM -aggregate-function.

I’d like it be done automatically whenever sheet #2 gets a new row.

So you should manually expand the Source of the Pivot in Advance to some sensefull size.

Thanks, if you could clarify (1) what does $E$??? signify explicitly? (2) Does food in this case stand for the second column of Sheet 2? (3) Can I use $Sheet1 regardless of what I named it?

instead Questionmarks take the highest Rownumber of the whole Lookup-range.

(2)
Yes, start with $B2 to get the data for ‘Oats’

(3)
No, I’m use a generic Name because I cannot know your concrete Sheetnames :wink: