def _create_grouped_output_selection_nrql(output_function, output_config,
    conditions):
    """Create a grouped output selection."""
    function = output_config['function']
    label = output_config.get('label')
    if label:
        label_nrql = f' AS `{label}`'
    else:
        label_nrql = ''
    condition = output_config['condition']
    if condition in conditions:
        condition_nrql = conditions[condition].nrql
    else:
        condition_nrql = condition
    return f'{output_function}({function}, WHERE {condition_nrql}){label_nrql}'
