def read_cube_name_from_mdx(mdx):
    """ Read the cubename from a valid MDX Query

    :param mdx: The MDX Query as String
    :return: String, name of a cube
    """

    mdx_trimed = ''.join(mdx.split()).upper()
    post_start = mdx_trimed.rfind("FROM[") + len("FROM[")
    pos_end = mdx_trimed.find("]WHERE", post_start)
    # if pos_end is -1 it works too
    cube_name = mdx_trimed[post_start:pos_end]
    return cube_name