Forum Discussion

daxdaxdax's avatar
daxdaxdax
Frequent Visitor
2 years ago
Solved

Parent Child Relationship PATH and Visual

Hi Community,   I am trying to create a power BI dashboard with data that has portfolio, parent and child. In the data, there are two columns for this projectcode and parent code For sample:   ...
  • OwenAuger's avatar
    OwenAuger
    2 years ago

    Hi again daxdaxdax 

    No problem, I have attached a sample PBIX 🙂

     

    I actually created two different methods in this file, but I will describe the first one which uses PATHCONTAINS, which is on the first page of the report.

     

    1. The relevant tables:

    Portfolio

    Parent Filter

    Unique projectcode values, used for selecting parent(s).

    Include Parent (parameter)

    This was created using the Parameter function, and the intention is to allow the user to include/exclude Parent on the fly.

    The values are formatted as:

    0 = Exclude Parent

    1 = Include Parent

     

    2. Measures

    The most important measure is Project Count with Parent Filter.

    The measure returns the count of Projects that are descendants of the Parent(s) selected from the Parent Filter table.

    Include Parent Value = 
    SELECTEDVALUE ( 'Include Parent'[Include Parent], 0 )
    Project Count = 
    COUNTROWS ( Portfolio )
    Project Count with Parent Filter = 
    -- Get Include Parent parameter value
    -- Include = 1
    -- Exclude = 0
    VAR IncludeParent =
        [Include Parent Value]
    -- Get the Project selection from the disconnected 'Parent Filter'
    VAR ParentSelection =
        VALUES ( 'Parent Filter'[projectcode] )
    -- Get the filtered values of Project & Path
    VAR ProjectPathValues =
        SUMMARIZE ( Portfolio, Portfolio[projectcode], Portfolio[Path] )
    -- Filter Project/Path to those that are descendants of Parent
    -- taking into account "Include Parent" parameter
    VAR ProjectPathFilter =
        FILTER (
            ProjectPathValues,
            VAR ParentInPath =
                NOT ISEMPTY (
                    FILTER (
                        ParentSelection,
                        PATHCONTAINS ( Portfolio[Path], 'Parent Filter'[projectcode] )
                    )
                )
            VAR ParentFlag =
                OR (
                    NOT Portfolio[projectcode] IN ParentSelection,
                    IncludeParent
                )
            RETURN
                AND ( ParentInPath, ParentFlag )
            
        )
    -- Return Project Count with the filter applied
    RETURN
        CALCULATE (
            [Project Count],
            KEEPFILTERS ( ProjectPathFilter )
    )

    3. Apply the measure to filter visuals

    The Project Count with Parent Filter measure can be applied in two ways:

    (a) As a visual level filter for visuals that are grouped by projectcode. The measure is filtered to >= 1.

    (b) By displaying the measure itself in a visual.

     

    For example, if we select Parent = 124 and choose "Exclude Parent", then visuals with this filter applied will show 125, 126, 127, 128:

     

    I hope that's along the lines of what you are looking for! It will no doubt need some tweaking for your model.

     

    Please post back if needed 🙂

     

    Regards