Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Ratio between Aggregated Columns #2994

Unanswered
momed-sakka asked this question in Q&A
Discussion options

Hi,

is it possible to create a column as a ratio between two columns (post aggregation) in pivot mode ?

Thanks.

You must be logged in to vote

Replies: 1 comment

Comment options

You may use a pivoted View as an input to Client::table, which can then calculate a ratio with an expression column.

const table = await worker.table(superstore_arrow);
const view = await table.view({ group_by: ["State"] });
const table2 = await worker.table(view, { index: "State (Group by 1)" });
await viewer.load(table2);
await viewer.restore({
 "filter": [["State (Group by 1)", "is not null", null]],
 "expressions": {
 "\"Sales\" / \"Profit\"": "\"Sales\" / \"Profit\""
 },
 "group_by": [
 "State (Group by 1)"
 ],
 "columns": [
 "\"Sales\" / \"Profit\""
 ],
})

This doesn't work well with real-time data yet, you must be careful to hook up both update and remove listeners and deal with group headers with filters, and set the index correctly. It also must be done during table construction, which makes it complicated to control the group_by from the UI (you can use a workspace or separate viewer, but this workflow is complex).

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /