Subquery - RETURN mapAccum and filter with it

Hello, I´ve a portion of a graph that I´m using a lot to filter by different date measurements

To avoid using the same code in different queries, I want to do it as a subQuery, the thing is that in the code I create a SumAccum to get a value to use later to filter when I´m traversing to the other part of the graph and I´m loosing that variable when I´m passing the MapAccum.

CREATE QUERY f_traverseDateVertex(
STRING timeBy = “Month”,
INT startTime = 202207,
INT endTime = 202208
)
FOR GRAPH SOP_WO_COVX
RETURNS (MapAccum<VERTEX, INT>)
{
//TYPEDEF TUPLE<VERTEX, INT time> Demand_Tuple;
MapAccum<VERTEX, INT> @@dates;

SumAccum
@getDate;

OrAccum
@visited,
@@done;

//Create the set of VERTICES “dates” with the type specified in timeBy (it should be one in “Day”, “Month”, “Year”, “Quarter”, “Week” or “Custom_Month”)
dates (ANY) = {timeBy};

//IF the input timeBy is “Day”, dates will contain only the days in the time frame startTime and endTime unless they are 0, then dates will have all the days in the DB
IF timeBy == “Day”
THEN
dates =
SELECT s
FROM Day:s
WHERE (startTime == 0 AND endTime ==0)
OR f_dateToInt(s.day) BETWEEN startTime AND endTime
ACCUM s.@getDate += f_dateToInt(s.day)
POST-ACCUM
@@dates += (s → f_dateToInt(s.day)); //Translate the date to an INT and store it in @dates so we can treat any kind of date parameter the same way
ELSE
WHILE dates.size() != 0 AND @@done == FALSE
DO

  dates = 
    SELECT t 
    FROM dates:s -(has)-:t
    WHERE s.type != timeBy                                                          //For the cases where we are hoping 2 times to get to Day, we don´t need to filter by the range of dates startTime and endTime
      OR (startTime == 0 AND endTime == 0 )                                         //If the user don´t give us a range of dates startTime and endTime it will get all the dates in that VERTEX
      OR (s.type == "Month" AND s.month BETWEEN startTime AND endTime)
      OR (s.type == "Year" AND s.year BETWEEN startTime AND endTime)
      OR (s.type == "Quarter" AND s.quarter BETWEEN startTime AND endTime)
      OR (s.type == "Custom_Month" AND s.custom_month BETWEEN startTime AND endTime)
      OR (s.type == "Week" AND s.week BETWEEN startTime AND endTime)
    ACCUM 
      CASE 
        WHEN s.type == timeBy AND s.type == "Month" THEN t.@getDate += s.month      //Since Month is the only VERTEX that can be in between the source timeBy VERTEX and Day, it´s necesary to add to @dates only when it´s the source VERTEX
        WHEN s.type == "Custom_Month" THEN t.@getDate += s.custom_month 
        WHEN s.type == "Week" THEN t.@getDate += s.week 
        WHEN s.type == "Quarter" THEN t.@getDate += s.quarter 
        WHEN s.type == "Year" THEN t.@getDate += s.year 
        ELSE t.@getDate += s.@getDate                                              //This case is when the input Parameter is Year or Quarter and the query needs to traverse through Month
      END,
      IF t.type == "Day"                                                           //When the target is Day (The VERTEX connected to hasOrders), the WHILE will stop
        THEN @@done += TRUE
      END;

  //If we check dates, it will contain all the posible VERTEX that the query allows to go, but we only need Day type VERTEX
  dates =
    SELECT d
    FROM dates:d
    WHERE d.type == "Day"
    POST-ACCUM
      @@dates += (d -> d.@getDate);
END; //END of WHILE

END;

PRINT @@dates;

RETURN @@dates;
}

Do you have any recomendations on how can I pass the Vertex and the @getDate value.

Thank you!