Search code examples
google-sheetsfiltergoogle-sheets-formulapivot-table

Query in Google sheets to select rows whose value didn't change over the last 30 days


I have this pivot table in one worksheet, and I want to write a query to select only those rows whose Logistic is US and whose values didn't change over the past 30 days and write it in another sheet of the same spreadsheet. Here is the link to the demo sheet with the pivot table and desired output. In the desired output sheet, I just manually pasted the filtered data by Logistic type US and looked up the EANs with the unchanged quantity for the past 30 days. So, the last date is 3/16/2023 that's why I considered the values from 2/16/2023.

I thought about comparing the value of each EAN in the most recent date with the values from the last 30 days. So, here are the conditions for the query:

  1. Filtering the table by the Logistic column = US
  2. Selecting EANs(rows) whose quantity(value) did not change over the last 30 days from the last Date column in the table
  3. Skipping over column S, which is for the date 3/2/2023, because it has no data

Can you please help me modify a query in Google sheets to achieve this? This formula below simply won't work because of this column S that has missing values and is included in the last 30 days range. I only want an exception for this particular column.

=filter('pivot table'!A3:W;
                'pivot table'!B3:B="US";
                 byrow(filter('pivot table'!C3:W;'pivot table'!C2:W2>max('pivot table'!C2:W2)-30);lambda(Σ;if(counta(Σ)=0;;and(countunique(Σ)=1;eq(counta(Σ);columns(Σ)))))))

Solution

  • Added formula to your output tab:

    =filter('pivot table'!A3:V;
                    'pivot table'!B3:B="US";
                     byrow(filter('pivot table'!C3:V;'pivot table'!C2:V2>max('pivot table'!C2:V2)-30);lambda(Σ;if(counta(Σ)=0;;and(countunique(Σ)=1;eq(counta(Σ);columns(Σ)))))))
    

    enter image description here