DEV Community

RITIK DHEDIA
RITIK DHEDIA

Posted on

What Happens Between a Raw CSV and a Dashboard?

A dashboard says you collected ₹750 on Monday. The payments export for that day adds up to ₹1,150. Both numbers can come from the same file. If ₹400 belongs to a failed payment, it should never make it into the collected amount.

Let’s follow four sample payments from a raw CSV to a daily total you can chart.
Start with one clear metric
We’ll calculate successful payment amount by date. Each row represents one payment in INR, and the date is already assigned in the export. We’ll add amounts only when the status is success.

Save this sample as payments.csv:

payment_id,payment_date,amount,status
p001,2026-11-30,500.00,success
p002,2026-11-30,400.00,failed
p003,2026-11-30,250.00,success
p004,2026-12-01,300.00,success
Enter fullscreen mode Exit fullscreen mode
Stage What happens to the sample
Read the CSV Python reads four payment rows.
Apply the metric rule Three rows qualify. The failed ₹400 payment is excluded.
Group by date November 30 has ₹500 + ₹250. December 1 has ₹300.
Write the dashboard table The output has two rows, one per date.

Turn the payment rows into daily totals
Save the script as build_daily_totals.py in the same directory. It uses Python’s standard library.

import csv
from collections import defaultdict
from decimal import Decimal

daily_totals = defaultdict(Decimal)

with open("payments.csv", newline="", encoding="utf-8") as source:
    for payment in csv.DictReader(source):
        if payment["status"].strip().lower() == "success":
            date = payment["payment_date"]
            daily_totals[date] += Decimal(payment["amount"])

with open("daily_payments.csv", "w", newline="", encoding="utf-8") as output:
    writer = csv.writer(output)
    writer.writerow(["payment_date", "successful_amount_inr"])
    for date, amount in sorted(daily_totals.items()):
        writer.writerow([date, f"{amount:.2f}"])
Enter fullscreen mode Exit fullscreen mode

Run python build_daily_totals.py. You should get this daily_payments.csv:

payment_date,successful_amount_inr
2026-11-30,750.00
2026-12-01,300.00
Enter fullscreen mode Exit fullscreen mode

DictReader gives each CSV row named fields, so the code can read payment["status"] directly. Decimal takes the amount as text and makes it possible to represent values like 0.10 exactly.
Put the result on a chart
Import daily_payments.csv into a spreadsheet or BI tool. Use payment_date on the horizontal axis and successful_amount_inr on the vertical axis. The first bar should be ₹750. If it shows ₹1,150, check whether the chart is reading the raw export or whether the filter was skipped.

Check one more detail before building on this example. A date with zero successful payments produces no row in this script. If your dashboard must show zero for that day, supply a complete date range and fill the missing dates explicitly. Likewise, if the export can include the same payment twice, define how to handle repeated payment IDs before summing amounts.

The next time you see a total on a dashboard, follow it back to the source. Which rows count? What does one output row represent? Those two answers will help you trace a surprising number back to the step that produced it.

Further reading

Top comments (1)

Collapse
 
dataspryva profile image
Dataspryva •

Ritik bhaiiya, The ₹750 daily collection figure rests on an unexamined assumption: the export's assigned date means collection date.