
Per creare una tabella pivot che mostri le ultime 4 settimane di dati (ovvero 4 settimane consecutive), puoi aggiungere una colonna helper ai dati di origine per contrassegnare i record nelle ultime 4 settimane, quindi utilizzare la colonna helper per filtrare i dati in la tabella pivot. Nell'esempio mostrato, la data corrente è il 25 agosto 2019 e la tabella pivot mostra 4 precedenti completi. Quando vengono aggiunti nuovi dati nel tempo, la tabella pivot continuerà a tenere traccia delle 4 settimane precedenti in base alla data corrente.
Campi
Nella tabella pivot mostrata, ci sono quattro campi nei dati di origine: Data, Vendite, Settimana e Filtro. Il filtro è una colonna helper con una formula che contrassegna le ultime 4 settimane. La settimana è una colonna di supporto che restituisce il lunedì per una determinata data (solo per comodità). Le vendite sono il campo del valore e la settimana è stata aggiunta come campo Riga da raggruppare per settimana:
Formula
La formula utilizzata in D5 (Settimana), copiata in basso, è:
=B5-WEEKDAY(B5,3)
Questa formula restituisce il lunedì della settimana per una determinata data.
La formula utilizzata in E5 (Filtro), copiata in basso, è:
=AND(B5>=TODAY()-WEEKDAY(TODAY(),3)-28,B5
This formula checks for dates in the last n weeks. It returns TRUE when a date is in the last 4 complete weeks, and FALSE if not. See the link for a full explanation.
Customizing week count
To customize the weeks displayed, adjust the Filter formula as needed to increase or decrease days. For example, to display the last 6 weeks (42 days), use:
=AND(B5>=TODAY()-WEEKDAY(TODAY(),3)-42,B5
Steps
Steps
Add helper column for Week with the formula above
Add helper column for Filter with the formula above
Create a pivot table
Add Sales as a Value field
Add Week as a Row field
Set number formatting for Week as desired
Add helper column as a Filter, filter on TRUE
Related pivots
Pivot table last 7 days To create a pivot table that shows the last 7 days of data (or, more generally, the last n days) you can add a helper column to the source data with a formula to flag records in the last 7 days, then use the helper column to filter the data in the…
Pivot table filter by weekday To create a pivot table with a filter for day of week (i.e. filter on Mondays, Tuesdays, Wednesdays, etc.) you can add a helper column to the source data with a formula to add the weekday name, then use the helper column to filter the data in the…
Pivot table last 12 months To create a pivot table that shows the last 12 months of data (i.e. a rolling 12 months), you can add a helper column to the source data with a formula to flag records in the last 12 months, then use the helper column to filter the data in the pivot…

Pivot Table Training
If you use Excel, but don't know how to use Pivot Tables, you're missing out… wasting time trying to do things that a Pivot Table can do for you automatically. Core Pivot is a step-by-step Excel video course that will teach you everything you need to know to use this powerful tool. With a small investment, Pivot Tables will pay you back again and again. See details here.