This paper focuses on the denoising of multidimensional data by a tensor subspace-based method. In a seminal work, multiway Wiener filtering was developed to minimize the mean square error between an expected signal tensor and the estimated tensor. It was then placed in a wavelet framework. The reliable estimation of the subspace rank for each mode and wavelet decomposition level is still pending. For the first time in this paper, we aim at estimating the subspace ranks for all modes of the tensor data by minimizing a least squares criterion. To solve this problem, we adapt particle swarm optimization. An application involving an RGB image and hyperspectral images exemplifies our method: we compare the results obtained in terms of signal to noise ratio with a slice-by-slice ForWaRD denoising.