Platform
Solutions
Resources
Pricing
Sign in
Sign up
Jonathan Terrell
Workspace
Fork
Published
General
By
Jonathan Terrell
Edited
Jan 29, 2022
Insert cell
Insert cell
Insert cell
tableY2020Q4
=
[
{
id1
:
"D"
,
id2
:
"H"
,
A
:
0
,
B
:
0
,
C
:
-
4
}
,
{
id1
:
"E"
,
id2
:
"I"
,
A
:
0
,
B
:
0
,
C
:
0
}
,
{
id1
:
"F"
,
id2
:
"J"
,
A
:
-
8
,
B
:
0
,
C
:
1
}
,
{
id1
:
"G"
,
id2
:
"K"
,
A
:
0
,
B
:
9
,
C
:
0
}
,
{
id1
:
"G"
,
id2
:
"L"
,
A
:
0
,
B
:
9
,
C
:
0
}
]
Insert cell
Insert cell
tableY2021Q4
=
[
{
id1
:
"D"
,
id2
:
"H"
,
A
:
0
,
B
:
0
,
C
:
1
}
,
{
id1
:
"E"
,
id2
:
"I"
,
A
:
0
,
B
:
0
,
C
:
0
}
,
{
id1
:
"F"
,
id2
:
"J"
,
A
:
1
,
B
:
0
,
C
:
2
}
,
{
id1
:
"G"
,
id2
:
"K"
,
A
:
0
,
B
:
3
,
C
:
0
}
,
{
id1
:
"G"
,
id2
:
"L"
,
A
:
0
,
B
:
3
,
C
:
0
}
]
Insert cell
Insert cell
rowCount
=
tableY2020Q4
.
length
Insert cell
Insert cell
{
const
result
=
[
]
;
for
(
let
index
=
0
;
index
<
rowCount
;
index
++
)
{
const
resultRow
=
{
id1
:
tableY2020Q4
[
index
]
.
id2
,
id2
:
tableY2020Q4
[
index
]
.
id2
}
;
if
(
tableY2020Q4
[
index
]
.
A
===
0
)
{
resultRow
.
A
=
0
;
}
else
{
resultRow
.
A
=
(
tableY2020Q4
[
index
]
.
A
-
tableY2021Q4
[
index
]
.
A
)
/
tableY2020Q4
[
index
]
.
A
;
}
if
(
tableY2020Q4
[
index
]
.
B
===
0
)
{
resultRow
.
B
=
0
;
}
else
{
resultRow
.
B
=
(
tableY2020Q4
[
index
]
.
B
-
tableY2021Q4
[
index
]
.
B
)
/
tableY2020Q4
[
index
]
.
B
;
}
if
(
tableY2020Q4
[
index
]
.
C
===
0
)
{
resultRow
.
C
=
0
;
}
else
{
resultRow
.
C
=
(
tableY2020Q4
[
index
]
.
C
-
tableY2021Q4
[
index
]
.
C
)
/
tableY2020Q4
[
index
]
.
C
;
}
result
.
push
(
resultRow
)
;
}
return
result
;
}
Insert cell
Insert cell
Insert cell
{
const
columnNames
=
[
"A"
,
"B"
,
"C"
]
;
const
resultTable
=
[
]
;
for
(
let
rowIndex
=
0
;
rowIndex
<
rowCount
;
rowIndex
++
)
{
const
resultRow
=
{
id1
:
tableY2020Q4
[
rowIndex
]
.
id2
,
id2
:
tableY2020Q4
[
rowIndex
]
.
id2
}
;
for
(
const
columnName
of
columnNames
)
{
if
(
tableY2020Q4
[
rowIndex
]
[
columnName
]
===
0
)
{
resultRow
[
columnName
]
=
0
;
}
else
{
resultRow
[
columnName
]
=
(
tableY2020Q4
[
rowIndex
]
[
columnName
]
-
tableY2021Q4
[
rowIndex
]
[
columnName
]
)
/
tableY2020Q4
[
rowIndex
]
[
columnName
]
;
}
}
resultTable
.
push
(
resultRow
)
;
}
return
resultTable
;
}
Insert cell
Insert cell
calcPeriodOnPeriodChange
=
(
table1
,
table2
,
columnNames
)
=>
{
const
resultTable
=
[
]
;
for
(
let
rowIndex
=
0
;
rowIndex
<
rowCount
;
rowIndex
++
)
{
const
resultRow
=
{
id1
:
table1
[
rowIndex
]
.
id1
,
id2
:
table1
[
rowIndex
]
.
id2
}
;
for
(
const
columnName
of
columnNames
)
{
if
(
table1
[
rowIndex
]
[
columnName
]
===
0
)
resultRow
[
columnName
]
=
0
;
else
resultRow
[
columnName
]
=
(
table1
[
rowIndex
]
[
columnName
]
-
table2
[
rowIndex
]
[
columnName
]
)
/
table1
[
rowIndex
]
[
columnName
]
;
}
resultTable
.
push
(
resultRow
)
;
}
return
resultTable
;
}
Insert cell
Insert cell
calcPeriodOnPeriodChange
(
tableY2020Q4
,
tableY2021Q4
,
[
"A"
,
"B"
,
"C"
]
)
Insert cell
Insert cell
calcPeriodOnPeriodChangeUsingMap
=
(
table1
,
table2
,
columnNames
)
=>
{
return
table1
.
map
(
(
table1Row
,
rowIndex
)
=>
{
const
resultRow
=
{
id1
:
table1Row
.
id1
,
id2
:
table1Row
.
id2
}
;
columnNames
.
map
(
(
columnName
)
=>
{
if
(
table1Row
[
columnName
]
===
0
)
resultRow
[
columnName
]
=
0
;
else
resultRow
[
columnName
]
=
(
table1Row
[
columnName
]
-
table2
[
rowIndex
]
[
columnName
]
)
/
table1Row
[
columnName
]
;
}
)
;
return
resultRow
;
}
)
;
}
Insert cell
calcPeriodOnPeriodChangeUsingMap
(
tableY2020Q4
,
tableY2021Q4
,
[
"A"
,
"B"
,
"C"
]
)
Insert cell
One platform
to build and deploy the best data apps
Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
tableY2020Q4
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
tableY2021Q4
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
rowCount
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
calcPeriodOnPeriodChange
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
calcPeriodOnPeriodChangeUsingMap
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML