Pycelonis Script : merge Analysis sheet from two different Analyses

Dear all,

If you already know, could you share your idea how to merge Analysis sheet from two different Analyses ?

I am managing template Analyses topic by topic (On-time delivery, Segregation of Duty etc.), and my client want to merge some of them and see the combined analysis.

I could copy analysis to text (JSON) file and could load back to Celonis as backup procedure. So I imagine I can do above when I copy to text, merge text and load back to Celonis.

Best regards,
Kazuhiko

Hi Kazuhiko,

maybe the pycelonis helps in that case. You could check whether the following article provides you support in that case:

https://python.celonis.cloud/docs/pycelonis/en/latest/notebooks/99_Use_Case_Copy_Analysis.html

In case you already have the analysis in the same team, I would probably go for the solution you proposed.

Best,

Justin

Dear Justin,

Thanks for your reply. I read this case study and enhanced my function below.

Best regards,
Kazuhiko

def merge_analysis(analysis_original, analysis_merged, analysis_new_name):
    """
    Merge two analyses and create new analysis as draft version.
    All features except for images are merged.

    Parameters
    ----------
    analysis_original : :class:`Analysis`
        To be copied all features
    analysis_merged : :class:`Analysis`
        To be copied formulas, variables, sheets, color mappings, palettes
    analysis_new_name : str
        name of new Analysis

    Returns
    -------
    :class:`Analysis`
        The newly created Analysis
    """

    # create empty analysis
    analysis_new = workspace.create_analysis(analysis_new_name)
    # inherit feature of original ananlysis
    analysis_new.draft.data['document'] = analysis_original.draft.data['document']
    # merge formulas
    formulas = analysis_original._saved_formula_data + analysis_merged._saved_formula_data
    for f in formulas:
        analysis_new.create_saved_formula(**f)
    # merge variables
    variables = analysis_original.draft.data['document']['variables'] + analysis_merged.draft.data['document']['variables']
    analysis_new.draft.data['document']['variables'] = variables
    # merge sheets
    sheets = analysis_original.draft.data['document']['components'] + analysis_merged.draft.data['document']['components']
    analysis_new.draft.data['document']['components'] = sheets
    # merge color mappings
    colorMappings = analysis_original.draft.data['document']['colorMappings'] + analysis_merged.draft.data['document']['colorMappings']
    analysis_new.draft.data['document']['colorMappings'] = colorMappings
    # merge palettes
    palettes = analysis_original.draft.data['document']['palettes'] + analysis_merged.draft.data['document']['palettes']
    analysis_new.draft.data['document']['palettes'] = palettes
    # return new analysis
    return analysis_new
2 Likes

Hi,
thanks for your input. I will discuss with my colleagues and see if we can include something like this in our next pycelonis release!.
Best Regards,

Simon

1 Like