KatInterview

Best Click Rate Day and Peak ISO Week in an Ad Log Using Pivots

SQL & DataModel answer
MediumModel answerSQL & Dataexcelpivot-tableiso-week

Last updated

Use Excel helper columns and PivotTables to find the day with the highest clicks per watch-minute and the ISO week with the most watch time, with deterministic tie-breaks.

You have a flat export of ad viewing activity with these columns:

  • Date: an Excel date with no time zone
  • UserID
  • AdID
  • WatchSeconds: integer, 0 or more
  • Clicks: integer, 0 or more

You may use only Excel (no Power Query). Describe precisely how you would do the following.

  1. Helper columns. Add these to the source data:

    • Weekday = WEEKDAY([@Date], 2) (Monday = 1)
    • ISOWeek = ISOWEEKNUM([@Date])
    • ISOYear = YEAR([@Date] + 4 - WEEKDAY([@Date], 2))

    Explain why ISOYear is needed around the turn of the year.

  2. Best click-rate day. Build a PivotTable that finds the single calendar date with the highest clicks per watch-minute, defined as (SUM Clicks) / (SUM WatchSeconds / 60). Use a PivotTable Calculated Field and give the exact formula string. If dates tie, the earliest date wins. Explain how you would enforce that deterministically.

  3. Peak week. Build a second PivotTable that totals WatchSeconds by ISOYear and ISOWeek and returns the week with the largest total. If weeks tie, the later week (by ISOYear, then ISOWeek) wins.

  4. Pitfalls. Give two ways that using WEEKNUM / WEEKDAY instead of ISO logic can yield wrong answers (for example weeks that straddle Dec/Jan, or locale-dependent week starts).

Report the two answers, the Top Date and the Top ISO Week (formatted ISOYear-W##), and lay out step by step the exact clicks-per-minute and total-WatchSeconds computations you would perform in the PivotTables.

Hints

Hint 1

A ratio of totals is not the same as the average of per-row ratios. Check how a Calculated Field aggregates before it evaluates its formula.

Hint 2

An ISO week belongs to the year containing its Thursday. Look at what adding 4 minus the Monday-based weekday does to any date.

Hint 3

Do not trust pivot sort order to break ties. Read the pivot output with a formula (MAX, then MIN or MAX over the matching rows), and round the ratio first to avoid floating-point noise.

Hint 4

Encode ISOYear and ISOWeek into one numeric key such as ISOYear*100+ISOWeek so that the 'later week' tie-break becomes a plain MAX.