import pandas as pd
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
dash = pd.read_csv("dashboard_data.csv")
dash["Fiscal Year"] = dash["Fiscal Year"].astype(str)
monthly = dash.groupby(["Fiscal Year", "Fiscal Month"], as_index=False)["Sales Amount"].sum()
ship_monthly = dash.groupby("Ship Month", as_index=False)["Sales Amount"].sum()
gl_monthly = dash.groupby("GL Month", as_index=False)["Sales Amount"].sum()
channel = dash.groupby(["Fiscal Year", "Sales Channel"], as_index=False)["Sales Amount"].sum()
product = dash.groupby(["Fiscal Year", "Product Type"], as_index=False)["Sales Amount"].sum()
recon = pd.DataFrame({
"Fiscal Year": ["2019", "2020", "2021"],
"Subledger": [28901.82, 27832.28, 35107.23],
"Income Statement": [30311.29, 27832.28, 35920.27],
})
recon_long = recon.melt(id_vars="Fiscal Year", var_name="Source", value_name="Revenue")
overview = vm.Page(
title="Overview",
components=[
vm.Card(text="2019 difference\n\n# -$1,409.47"),
vm.Card(text="2021 difference\n\n# -$813.04"),
vm.Card(text="Combined difference\n\n# -$2,222.51"),
vm.Graph(title="Monthly sales by fiscal year", figure=px.line(monthly, x="Fiscal Month", y="Sales Amount", color="Fiscal Year", markers=True)),
vm.Graph(title="Subledger vs. income statement", figure=px.bar(recon_long, x="Fiscal Year", y="Revenue", color="Source", barmode="group")),
],
layout=vm.Grid(grid=[[0, 0, 1, 1, 2, 2],
[3, 3, 3, 4, 4, 4],
[3, 3, 3, 4, 4, 4],
[3, 3, 3, 4, 4, 4]]),
)
dates = vm.Page(
title="Ship & GL Dates",
components=[
vm.Graph(title="Monthly sales by shipped date", figure=px.line(ship_monthly, x="Ship Month", y="Sales Amount", markers=True)),
vm.Graph(title="Monthly sales by GL posted date", figure=px.line(gl_monthly, x="GL Month", y="Sales Amount", markers=True)),
],
layout=vm.Grid(grid=[[0], [1]]),
)
breakdown = vm.Page(
title="Channel & Product",
components=[
vm.Graph(title="Sales by channel", figure=px.bar(channel, x="Fiscal Year", y="Sales Amount", color="Sales Channel", barmode="group")),
vm.Graph(title="Sales by product type", figure=px.bar(product, x="Product Type", y="Sales Amount", color="Fiscal Year", barmode="group")),
],
layout=vm.Grid(grid=[[0, 1]]),
controls=[vm.Filter(column="Fiscal Year")],
)
risk_page = vm.Page(
title="Risk Assessment",
components=[
vm.Card(text="""
Risk level: Significant Risk
I didn't change my risk level because the client's answers didn't clear up any issues I brought up and based previous assessment on. The client provided two different reasons for the wrong GL Posted dates, manual error and system glitch, and the control they mention in their reply is still being worked on, so the 2019-2021 report has only a senior reviewing it. Customer sales rep 1004989 had 15 different sales to 15 different customers at 15 different stores. The client says that this rep has returning customers and does extra time that is why they have high sales but that does not match the data because there are no returning customers. They said that there is a month end spike in sales but that information also does not match the data and does not show any markdowns to boost sales. The client also said a senior reviews every transaction but that seems highly unlikely for a company with 200 plus stores and many transactions across them. One person checking the transactions is not a good control nor is it effective. The post COVID boost answer makes sense, but even that needs further proof because difference in sales from previous years is way above materiality. I need more evidence like sales receipts and logs from Q4, more information on CSR 1004989, and a complete revenue report.
""", extra={"style": {"fontSize": "18px"}}),
],
)
dashboard = vm.Dashboard(
pages=[overview, dates, breakdown, risk_page],
title="KeyKey Lime Case Study",
navigation=vm.Navigation(nav_selector=vm.NavBar(position="top")),
)
Vizro().build(dashboard).run()