I’m looking to find the most recent entry in a Google Sheet. Currently, the “Find” function returns the very first row in the Google Sheet for a given search query, but I want to get the last row for that query. The lookup should be performed from the bottom (end of the rows) towards the top.
A simple way to retrieve the data from the last row of a Google Sheet is to first retrieve all the data from the sheet and then use the following code block to extract the last row with values.
export const code = async (inputs) => {
// Get the data from the previous step (assuming it is passed as inputs.values)
const rows = inputs.values;
// Variable to hold the last row with data
let lastRow = null;
// Iterate through the rows in reverse to find the last non-empty row
for (let i = rows.length - 1; i >= 0; i--) {
// Check if any cell in the row is not empty
if (rows[i].some(cell => cell.trim() !== "")) {
lastRow = rows[i];
break;
}
}
// Return the last row with values
return lastRow;
};
This will check all the rows and return the last row that contains data, allowing you to easily extract the most recent row with values.
Let me know if you need any further clarification!