So this is a tad more complicated than the title suggests so try to follow along. On this sheet, I’m trying to get cells `D4:G4`

to show the most recent 4 weeks with data on my spreadsheet. My formula below has a few things going on. First, it counts all of the non blank cells in row `14`

from `L14:BV14`

. Second, it uses the `OFFSET()`

function to go to the corresponding header in the **date** row `2`

. Third, it checks to see if it is a valid date or if it equals `Total`

. Forth, if it doesn’t equal “Total” , it returns that date. *This is where I am struggling.* If **not**, it `-1`

within the `OFFSET()`

function and displays that date. The issue is depending on where the data lies, it either needs to `+1`

OR `-1`

. Because it can’t distinguish this, two of the cells will display the same date if one of them lies on a `Total`

cell. The following is my current formula for cell `D4`

. `=IF(SUMPRODUCT(($ L14:$ BW14<>"")+0) >= 4,IF(TO_DATE(OFFSET($ K$ 2,,SUMPRODUCT(--({$ L$ 14:$ BV$ 14}<>""))-3)) = "Total", TO_DATE(OFFSET($ K$ 2,,SUMPRODUCT(--({$ L$ 14:$ BV$ 14}<>""))-2)), TO_DATE(OFFSET($ K$ 2,,SUMPRODUCT(--({$ L$ 14:$ BV$ 14}<>""))-3))),IF(SUMPRODUCT(($ L14:$ BW14<>"")+0) = 3,IF(TO_DATE(OFFSET($ K$ 2,,SUMPRODUCT(--({$ L$ 14:$ BV$ 14}<>""))-2)) = "Total", TO_DATE(OFFSET($ K$ 2,,SUMPRODUCT(--({$ L$ 14:$ BV$ 14}<>""))-1)), TO_DATE(OFFSET($ K$ 2,,SUMPRODUCT(--({$ L$ 14:$ BV$ 14}<>""))-2))),IF(SUMPRODUCT(($ L14:$ BW14<>"")+0) = 2,IF(TO_DATE(OFFSET($ K$ 2,,SUMPRODUCT(--({$ L$ 14:$ BV$ 14}<>""))-1)) = "Total", TO_DATE(OFFSET($ K$ 2,,SUMPRODUCT(--({$ L$ 14:$ BV$ 14}<>"")))), TO_DATE(OFFSET($ K$ 2,,SUMPRODUCT(--({$ L$ 14:$ BV$ 14}<>""))-1))),IF(SUMPRODUCT(($ L14:$ BW14<>"")+0) = 1,IF(TO_DATE(OFFSET($ K$ 2,,SUMPRODUCT(--({$ L$ 14:$ BV$ 14}<>"")))) = "Total", TO_DATE(OFFSET($ K$ 2,,SUMPRODUCT(--({$ L$ 14:$ BV$ 14}<>""))+1)), TO_DATE(OFFSET($ K$ 2,,SUMPRODUCT(--({$ L$ 14:$ BV$ 14}<>""))))),IF(SUMPRODUCT(($ L14:$ BW14<>"")+0) < 1,"")))))`