SECTION 07 / 13

Group totals: maximum revenue is a different question

2 min read
On this page 4 headings

A group count adds 1 per record. A group total adds an amount from the record. A shop can have fewer bills yet more revenue if those bills are larger.

The actual 30 shopping bills give separate store totals of ₹7,120, ₹13,284 and ₹4,009; altogether ₹24,413.
The actual 30 shopping bills give separate store totals of ₹7,120, ₹13,284 and ₹4,009; altogether ₹24,413.
YOUR COURSE DATA · TRY IT HERE

Add bill amounts separately for each store

Use the supplied 30 shopping bills. No download or coding is needed.

READY TO START

A pile of 30 cards

Start with the first card. Read its fields, do one small action, then move on.

What we remember

Read
0

Nothing has been read yet. Choose Next card to begin.

Look through all 30 original records
Bill 1SV Stores · ₹567
BillNo
1
Store
SV Stores
Customer
Srivatsan
BillAmount
567
MajorCategories
Apparel | Food | Toiletries
FoodClass
Mixed
Bill 2Big Bazaar · ₹1525
BillNo
2
Store
Big Bazaar
Customer
Sudeep
BillAmount
1525
MajorCategories
Apparel | Food | Household
FoodClass
Mixed
Bill 3SV Stores · ₹1341
BillNo
3
Store
SV Stores
Customer
Akshaya
BillAmount
1341
MajorCategories
Food | Toiletries
FoodClass
Mixed
Bill 4SV Stores · ₹123
BillNo
4
Store
SV Stores
Customer
Advaith
BillAmount
123
MajorCategories
Food
FoodClass
All food
Bill 5Big Bazaar · ₹4174
BillNo
5
Store
Big Bazaar
Customer
Akshaya
BillAmount
4174
MajorCategories
Apparel | Food | Household
FoodClass
Mixed
Bill 6Sun General · ₹354
BillNo
6
Store
Sun General
Customer
Srivatsan
BillAmount
354
MajorCategories
Electronics | Food | Stationery | Utilities
FoodClass
Mixed
Bill 7SV Stores · ₹96
BillNo
7
Store
SV Stores
Customer
Akhil
BillAmount
96
MajorCategories
Food
FoodClass
All food
Bill 8Big Bazaar · ₹3132
BillNo
8
Store
Big Bazaar
Customer
Advaith
BillAmount
3132
MajorCategories
Apparel | Food | Toiletries
FoodClass
Mixed
Bill 9Big Bazaar · ₹595
BillNo
9
Store
Big Bazaar
Customer
Mohith
BillAmount
595
MajorCategories
Apparel | Food
FoodClass
Mixed
Bill 10Sun General · ₹378
BillNo
10
Store
Sun General
Customer
Rajesh
BillAmount
378
MajorCategories
Food | Stationery
FoodClass
Mixed
Bill 11SV Stores · ₹893
BillNo
11
Store
SV Stores
Customer
Abhinav
BillAmount
893
MajorCategories
Food | Household
FoodClass
Mixed
Bill 12Sun General · ₹186
BillNo
12
Store
Sun General
Customer
Aparna
BillAmount
186
MajorCategories
Food | Household | Stationery
FoodClass
Mixed
Bill 13Big Bazaar · ₹3060
BillNo
13
Store
Big Bazaar
Customer
Abhinav
BillAmount
3060
MajorCategories
Apparel
FoodClass
No food
Bill 14Sun General · ₹656
BillNo
14
Store
Sun General
Customer
Vignesh
BillAmount
656
MajorCategories
Electronics | Grooming | Stationery | Utilities
FoodClass
No food
Bill 15Sun General · ₹229
BillNo
15
Store
Sun General
Customer
Abhinav
BillAmount
229
MajorCategories
Toiletries
FoodClass
No food
Bill 16Sun General · ₹187
BillNo
16
Store
Sun General
Customer
Advaith
BillAmount
187
MajorCategories
Stationery
FoodClass
No food
Bill 17SV Stores · ₹279
BillNo
17
Store
SV Stores
Customer
George
BillAmount
279
MajorCategories
Food
FoodClass
All food
Bill 18SV Stores · ₹603
BillNo
18
Store
SV Stores
Customer
Ahmed
BillAmount
603
MajorCategories
Food
FoodClass
All food
Bill 19SV Stores · ₹592
BillNo
19
Store
SV Stores
Customer
Neeraja
BillAmount
592
MajorCategories
Cosmetics | Food
FoodClass
Mixed
Bill 20SV Stores · ₹622
BillNo
20
Store
SV Stores
Customer
Ahmed
BillAmount
622
MajorCategories
Food | Toiletries
FoodClass
Mixed
Bill 21SV Stores · ₹128
BillNo
21
Store
SV Stores
Customer
Akshaya
BillAmount
128
MajorCategories
Food
FoodClass
All food
Bill 22Sun General · ₹315
BillNo
22
Store
Sun General
Customer
Suresh
BillAmount
315
MajorCategories
Food | Household | Utilities
FoodClass
Mixed
Bill 23SV Stores · ₹888
BillNo
23
Store
SV Stores
Customer
Julia
BillAmount
888
MajorCategories
Food
FoodClass
All food
Bill 24SV Stores · ₹92
BillNo
24
Store
SV Stores
Customer
Neeraja
BillAmount
92
MajorCategories
Food
FoodClass
All food
Bill 25Sun General · ₹1364
BillNo
25
Store
Sun General
Customer
Ahmed
BillAmount
1364
MajorCategories
Accessories | Electronics | Stationery
FoodClass
No food
Bill 26SV Stores · ₹276
BillNo
26
Store
SV Stores
Customer
Srivatsan
BillAmount
276
MajorCategories
Food
FoodClass
All food
Bill 27Sun General · ₹340
BillNo
27
Store
Sun General
Customer
Srivatsan
BillAmount
340
MajorCategories
Household
FoodClass
No food
Bill 28SV Stores · ₹514
BillNo
28
Store
SV Stores
Customer
Vignesh
BillAmount
514
MajorCategories
Food | Toiletries
FoodClass
Mixed
Bill 29SV Stores · ₹106
BillNo
29
Store
SV Stores
Customer
Ahmed
BillAmount
106
MajorCategories
Food
FoodClass
All food
Bill 30Big Bazaar · ₹798
BillNo
30
Store
Big Bazaar
Customer
Radha
BillAmount
798
MajorCategories
Food
FoodClass
All food
The lecture’s store with most bills is different from the store with greatest revenue.
The lecture’s store with most bills is different from the store with greatest revenue.

Replace increments with additions

Totals = empty table
MaxRevenue = 0
For each bill X {
    store = X.Store
    If store has no total: Totals[store] = 0
    Totals[store] = Totals[store] + X.BillAmount
    if (Totals[store] > MaxRevenue) {
        MaxRevenue = Totals[store]
    }
}

Only the current store total changes. For nonnegative bill amounts, its total can only increase, so comparing that total against MaxRevenue maintains the best value in one pass. If negative refunds are allowed, a former leader can decrease; this shortcut needs rethinking rather than being applied blindly.

Distinguish four amounts

QuantityWhat it means
Individual bill amountOne purchase total.
Store revenueSum of all its bill amounts.
Average bill for a storeIts revenue divided by its number of bills.
Maximum revenue across storesLargest completed store total.

Worked example with small bills

BillStoreAmountA totalB totalMaxRevenue
1A4040040
2B10040100100
3A3575100100
4A30105100105

A has more bills and final revenue 105; B has one bill with amount 100. Average bills are 105/3 = 35 for A and 100 for B. “Best store” must be defined by a chosen metric.

Apply the pattern to words

Tutorial 2.4 sums LetterCount separately for every part of speech. This asks which category contributes the most letters, not simply the most word cards. From the supplied Words table, noun letters total 145, adjective letters 65, verb letters 35, preposition letters 27, article letters 18, pronoun letters 17, adverb letters 13 and conjunction letters 9.

Those category letter totals sum to 329, matching the whole paragraph. Nouns contribute the most letters. A category can be common but contain short words, so occurrence frequency and total letter contribution are distinct summaries.

Try it yourself

Three A bills are 20,30,40; one B bill is 100. Which wins by bill count and by revenue?

Show explained answer

A wins by count: 3 versus 1. B wins by revenue: 100 versus 90.

Try it yourself

A category has words of lengths 2,2,3. What are its frequency and letter contribution?

Show explained answer

Frequency=3 words; letter contribution=7 letters.

Try it yourself

Why is a running maximum of group totals straightforward for nonnegative bills?

Show explained answer

A group total never falls, so an existing maximum cannot be invalidated by a decrease. Only the changed total can improve it.

Try it yourself

Which part of speech contributes the most letters in Words.pdf?

Show explained answer

Noun, with a total LetterCount of 145. That is a sum of lengths, not a count of 145 words.

Source: Lecture 2.5; Tutorial 2.4. Small teaching datasets and diagrams are prepared for these notes; lecture and tutorial totals are identified explicitly.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑