
Get row(s) 액션 사용Get row(s) 출력값(JSON 배열)을 확인 → 모든 데이터는 이미 들어와 있음map(i => i.json)으로 데이터 추출수정전
const expenseRecords = Array.isArray($node["Expense Records"].json)
? $node["Expense Records"].json
: [$node["Expense Records"].json];const expenseRecords = Array.isArray($node["Expense Records"].json)
? $node["Expense Records"].json
: [$node["Expense Records"].json];수정후
// Google Sheets 노드에서 전체 데이터 가져오기
const expenseRecords = $items("Expense Records", 0).map(i => i.json);
// 이번 달 기준
const now = new Date();
const thisMonth = now.getMonth();
const thisYear = now.getFullYear();
// 누적 변수
let monthSum = 0;
expenseRecords.forEach(row => {
const rowDate = new Date(row.날짜 || row.date);
if (!rowDate.getTime()) return;
// 이번 달 데이터만 합산
if (rowDate.getFullYear() === thisYear && rowDate.getMonth() === thisMonth) {
monthSum += parseFloat(row.금액 || row.amount) || 0;
}
});
return [{
json: {
월누적합: monthSum
}
}];// Google Sheets 노드에서 전체 데이터 가져오기
const expenseRecords = $items("Expense Records", 0).map(i => i.json);
// 이번 달 기준
const now = new Date();
const thisMonth = now.getMonth();
const thisYear = now.getFullYear();
// 누적 변수
let monthSum = 0;
expenseRecords.forEach(row => {
const rowDate = new Date(row.날짜 || row.date);
if (!rowDate.getTime()) return;
// 이번 달 데이터만 합산
if (rowDate.getFullYear() === thisYear && rowDate.getMonth() === thisMonth) {
monthSum += parseFloat(row.금액 || row.amount) || 0;
}
});
return [{
json: {
월누적합: monthSum
}
}];$items()처럼 전체 배열을 코드에서 순회하는 방법으로 해결 가능하다TIL
n8n
GoogleSheet
JavaScript
JSON
데이터처리
자동화