There is no formula, 'per se', for calculating Flex Temp (or Assumed Temp if you're Boeing).
For each runway direction that the aircraft operator will use, Airbus, Boeing, or the performance engineering provider will conduct an airport analysis, considering Runway characteristics (Length, Stopway, Clearway, Slope, etc.), obstacles, acceleration altitudes, Pressure Height, Temperature, for each Takeoff Flap setting and for a standard series of wind components.
So far, in this this much simplified paragraph, the performance engineer would have had to refer to thousands of formulas, and tens of thousands of data extraction points from the Airplane Performance Manual or AFM.
From this runway analysis (discretely different from all other runways even if their physical characteristics seem to be the same), the performance engineer produces RTOWs (Regulated Takeoff Weights), being the limiting weights in a Temperature / Wind Component matrix.
Thus, for a particular runway, the pilot can extract from the RTOW, the performance limited takeoff weight for a data pair of Temperature and Wind.
If, on a given day, the Actual Takeoff Weight (ATOW) is below the limiting weight (RTOW), the pilot may set the thrust to that which would be delivered at the temperature at which the ATOW equals the RTOW, for example,
ATOW is 200.0 T, OAT is 20°C
RTOW at 20°C is 250.0 T, I am well under the performance limit.
RTOW at 42°C is 200.0 T, if the temperature increases to 42°C I can still go, or ALTERNATIVELY, if I only use the thrust that the engine would produce at 42°C I can still go, and use much less thrust in doing so. Therefor I will 'Flex' my Airbus engines to 42°C, or tell my Boeing engines that they may 'Assume' the temperature to be 42°C.
This has been long-winded. It was deliberately long-winded, but even so, fell far short of establishing the extremely complex business of performance engineering when it comes to Airport Analysis. There are no formulae, the process requires countless applications of formulae and application of performance data. Even when some formulae do work, a 'break point' will always jump up to cut off your formula when you least expect it.
Pilots (I'm one of 'em, but also a performance engineer), love to reduce complexities to simple and quick formulae. 99% of the time they will work within practical limits, the other 1% of the time, they can kill you.