def unstack(self, dim=None):
        """
        Unstack existing dimensions corresponding to MultiIndexes into
        multiple new dimensions.

        New dimensions will be added at the end.

        Parameters
        ----------
        dim : str or sequence of str, optional
            Dimension(s) over which to unstack. By default unstacks all
            MultiIndexes.

        Returns
        -------
        unstacked : Dataset
            Dataset with unstacked data.

        See also
        --------
        Dataset.stack
        """

        if dim is None:
            dims = [d for d in self.dims if isinstance(self.get_index(d),
                                                       pd.MultiIndex)]
        else:
            dims = [dim] if isinstance(dim, str) else dim

            missing_dims = [d for d in dims if d not in self.dims]
            if missing_dims:
                raise ValueError('Dataset does not contain the dimensions: %s'
                                 % missing_dims)

            non_multi_dims = [d for d in dims if not
                              isinstance(self.get_index(d), pd.MultiIndex)]
            if non_multi_dims:
                raise ValueError('cannot unstack dimensions that do not '
                                 'have a MultiIndex: %s' % non_multi_dims)

        result = self.copy(deep=False)
        for dim in dims:
            result = result._unstack_once(dim)
        return result