Reshape an Excel table between wide and long formats

Autor: AILesson7 Min. EinrichtungszeitGetestet mit:ChatGPTGeprüft am: 2026-08-28

Schnelle Antwort

Unpivot or pivot data while protecting record grain, identifiers, null meaning, and aggregation rules. Angeben: Source schema and samples, Target schema and use, Keys, labels, blanks, and aggregation. Erwartetes Ergebnis: A reversible reshape plan with Power Query steps, key checks, and row-count reconciliation.

1

Kontext hinzufügen

Dein Text bleibt in diesem Browser. AILesson Prompts sendet ihn nicht an ein Modell oder einen Server.

2

Dein Prompt

Nicht ausgefüllte Felder bleiben als Platzhalter sichtbar, sodass du den Prompt weiterhin kopieren und bearbeiten kannst.

Design an Excel reshape from wide to long or long to wide using the supplied schema and rules.

Headers, types, grain, keys, measures, samples, blanks, and errors:
[source]

Target orientation, columns, order, downstream use, refresh, and reversibility:
[target]

Unique keys, label parsing, null/zero, duplicates, units, totals, aggregation, and validation:
[rules]

State the source and target record grain before proposing steps. For wide-to-long, separate identifier columns from measure columns and define how original headers become attribute fields; do not unpivot totals or notes accidentally. For long-to-wide, prove that each row-key and new-column combination is unique or apply only an explicitly approved aggregation. Preserve null versus zero, data types, units, and source labels. Prefer Power Query for refreshable transformations and provide menu-level steps plus key M operations when useful; use formulas only if the stated environment warrants them. Return: grain and key audit; source-to-target mapping; transformation steps; duplicate and header-parsing policy; expected row/column reconciliation; validation queries; sample output; refresh/reversal notes; and failure conditions that should stop the reshape.
Im Playground ausprobieren
Standardmäßig privatDer Prompt wird lokal in deinem Browser zusammengestellt. Gib keine vertraulichen Informationen in einen KI-Dienst ein, es sei denn, deine Organisation erlaubt dies.

Von der Eingabe zum Ergebnis

Ein ausgearbeitetes Beispiel

Sieh dir an, wie konkreter Kontext dieses Rezept in ein nutzbares Ergebnis verwandelt.

Tatsächliche Eingabe

Source schema and samples
Excel Table QuarterlyTargets, one row per Product ID + Region. Columns: Product ID text, Region text, Owner text, Q1 Target whole number, Q2 Target whole number, Q3 Target whole number, Q4 Target whole number, Annual Total formula, Notes text. 120 rows. Product ID + Region is unique. Q2 may be blank meaning target not set; zero means explicitly no target. No formula errors. Example P-01, East, Ana, 100, blank, 0, 140, 240, launch delayed.
Target schema and use
Wide to long for Power BI. Target columns Product ID, Region, Owner, Quarter, Target, Notes. One row per product-region-quarter, keeping blank target rows so missingness can be analyzed. Refresh monthly from the Excel Table. Annual Total must not become a quarter. Reversal to original four quarter columns should be possible, but Annual Total may be recalculated.
Keys, labels, blanks, and aggregation
Quarter headers must map exactly Q1 Target -> Q1 through Q4 Target -> Q4. Do not aggregate. Product ID + Region + Quarter must be unique. Preserve Target as nullable whole number and zero as zero. Owner and Notes repeat across quarter rows. Validate 120×4=480 rows and exactly four quarters per source key.

Beispielausgabe

Grain audit: source key is Product ID + Region; target key is Product ID + Region + Quarter. Owner and Notes are descriptive attributes repeated by design. Annual Total is derived metadata and excluded from unpivot. Expected target is exactly 480 rows, including null targets.

Power Query steps: load QuarterlyTargets with Data > From Table/Range. Set Product ID, Region, Owner, Notes to text; Q1–Q4 Target to nullable whole number. Select Product ID, Region, Owner, Annual Total, Notes, then choose Unpivot Other Columns only after confirming the “other” set is exactly the four quarter columns; a safer refresh-resistant approach is explicitly select Q1 Target through Q4 Target and choose Unpivot Columns. Rename Attribute to Quarter Source and Value to Target. Map the four allowed header values to Q1–Q4; if any other value appears, return an error rather than trimming arbitrary text. Remove Annual Total after retaining it only for reconciliation, then order target columns. Do not filter null Target rows.

Validation: group by Product ID, Region, Quarter and stop if any count differs from 1. Group by source key and require four rows. Require row count 480, allowed Quarter set Q1–Q4, and whole-number-or-null Target. Recalculate non-null quarterly sum and compare with source Annual Total while treating null as missing, not automatically zero; for P-01 the long rows are Q1=100, Q2=null, Q3=0, Q4=140, with Owner Ana and Notes repeated. Reverse by pivoting Quarter using Target only after uniqueness passes and “Don't Aggregate” is available; recalculate Annual Total under an approved null rule.

Warum das funktioniert

  1. 1

    Declaring grain before reshaping prevents repeated-looking rows from being mistaken for duplicates.

  2. 2

    Row-count and key reconciliation detects dropped measures, accidental totals, and unauthorized aggregation.

Ergebnis prüfen

  • Are identifier, measure, metadata, total, and note columns classified before transformation?

  • Is every long-to-wide row-key/column-key combination unique or explicitly aggregated?

  • Do source and target reconcile for keys, non-null measures, zeros, totals, and units?

Sicher nutzen

Häufig gestellte Fragen

Praktische Antworten dazu, wann du dieses Rezept verwenden solltest, was du bereitstellen solltest und wo menschliche Prüfung weiterhin wichtig ist.

What should I prepare before using “Reshape an Excel table between wide and long formats”?

For “Reshape an Excel table between wide and long formats,” prepare Source schema and samples, Target schema and use, and Keys, labels, blanks, and aggregation. Replace placeholders only with information you can verify. If a detail is unknown, preserve that uncertainty explicitly instead of asking the model to infer it.

When is the “Reshape an Excel table between wide and long formats” result not ready to use?

The result is not ready if it does not yet deliver the stated outcome—A reversible reshape plan with Power Query steps, key checks, and row-count reconciliation—from the supplied evidence, or if it relies on unresolved assumptions, missing approvals, or invented details. Use the checks as release gates: revise the source inputs or assign a named, authorized reviewer instead of polishing an unsupported output.

Which AI tools have recorded tests for “Reshape an Excel table between wide and long formats”?

The published test record for “Reshape an Excel table between wide and long formats” lists ChatGPT as of 2026-08-28. This confirms recorded runs, not guaranteed compatibility or identical results in later product versions. For another tool or version, keep every constraint visible and repeat the result checks before use.

Weitere Möglichkeiten zum Entdecken

Wo dieses Rezept hineinpasst

Bring die Arbeit voran