def unstack_and_count(da, dims):
    """ Unstacks provided xarray object and returns the total number of elements along dims """
    try:
        unstacked = da.unstack(da.dims[0])
    except ValueError:
        unstacked = da
    if dims is None:
        return 0 * unstacked + 1
    else:
        return (0 * unstacked + 1).sum(dim=dims, skipna=True)
