def reference_type_alias(metric, reference):
    """
    Format a metric key for a subquery selection in case of a reference.

    :return:
        A string that is used as the selector for a field in a blended subquery.
    """
    key = metric.alias
    if reference is None:
        return key
    return '{}_{}'.format(key, reference.reference_type.alias)
