Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

How to summarize values with a Matrix when data is in three different tables?

I am trying to summarize values across a hierarchy in a Maxtrix, but am having trouble with the relationships.  I have three tables with just the applicable columns listed: Stories: Key ABC...
  • Anonymous's avatar
    Anonymous
    1 year ago

    Hi Anonymous 

     

    Please try this measure:

    MEASURE =
    VAR _PK =
        SELECTEDVALUE ( 'Sub-Tasks'[Parent Key] )
    VAR _K =
        SELECTEDVALUE ( 'Sub-Tasks'[Key] )
    VAR _vtable =
        SELECTCOLUMNS (
            FILTER (
                CROSSJOIN ( ALLSELECTED ( 'Sub-Tasks' ), ALLSELECTED ( 'Time Spent' ) ),
                'Sub-Tasks'[Key] = 'Time Spent'[Key]
            ),
            "__Key", 'Sub-Tasks'[Parent Key],
            "__Hours", 'Time Spent'[Hours]
        )
    RETURN
        IF (
            ISINSCOPE ( 'Sub-Tasks'[Key] ),
            CALCULATE (
                SUM ( 'Time Spent'[Hours] ),
                FILTER ( ALLSELECTED ( 'Time Spent' ), 'Time Spent'[Key] = _K )
            ),
            CALCULATE (
                SUM ( 'Time Spent'[Hours] ),
                FILTER ( ALLSELECTED ( 'Time Spent' ), 'Time Spent'[Key] = _PK )
            )
                + SUMX ( FILTER ( _vtable, [__Key] = _PK ), [__Hours] )
        )
    

    Then create a matrix with the field [Parent Key]and [Key] from 'Sub-Tasks', the result is as follow:

     

     

    Best Regards

    Zhengdong Xu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.