What I’m trying to do
I have client proposals that I’ve written over the course of the year, and I’d like a table that shows me how many proposals I’ve submitted and the total amount of the proposals grouped by either Pending, Won, or Lost. I have very little knowledge of coding, so any help would be much appreciated!
Things I have tried
I have tried simple and complex things (with help from ChatGPT and Copilot), but I haven’t gotten anything to work. Here are some of the pieces…
How the property looks in the proposal note template:
The simple solution does not populate the amounts. I do get lines for the various statuses, but there’s no summation of the the totals. Here’s the code:
table without id
Status,
sum(Proposal-Amount) as "Total Amount"
from "Proposals"
group by Status
sort Status asc
I also tried a couple complex solutions that errored out. Here are the two solutions:
const dvApi = this.app.plugins.plugins.dataview.api;
const proposalPages = dvApi.pages('"Proposals"');
const pendingAmount = proposalPages.where(p => p.Status == "Pending").sum(p => p.Amount);
const wonAmount = proposalPages.where(p => p.Status == "Won").sum(p => p.Amount);
const lostAmount = proposalPages.where(p => p.Status == "Lost").sum(p => p.Amount);
const totalAmount = pendingAmount + wonAmount + lostAmount;
const table = dvApi.container.createEl("table");
const headerRow = table.createEl("tr");
headerRow.createEl("th", { text: "Status" });
headerRow.createEl("th", { text: "Total Amount" });
const addRow = (status, amount) => {
const row = table.createEl("tr");
row.createEl("td", { text: status });
row.createEl("td", { text: amount });
};
addRow("Pending", pendingAmount);
addRow("Won", wonAmount);
addRow("Lost", lostAmount);
addRow("Total", totalAmount);
dvApi.container.appendChild(table);
const dvApi = this.app.plugins.plugins.dataview.api;
const proposalPages = dvApi.pages('"Proposals"');
const pendingAmount = proposalPages.where(p => p.Status == "Pending").map(p => p.Amount).reduce((a, b) => a + b, 0);
const wonAmount = proposalPages.where(p => p.Status == "Won").map(p => p.Amount).reduce((a, b) => a + b, 0);
const lostAmount = proposalPages.where(p => p.Status == "Lost").map(p => p.Amount).reduce((a, b) => a + b, 0);
const totalAmount = pendingAmount + wonAmount + lostAmount;
dvApi.table(["Status", "Total Amount"], [
["Pending", pendingAmount],
["Won", wonAmount],
["Lost", lostAmount],
["Total", totalAmount]
]);