Forum Discussion
How to summarize values with a Matrix when data is in three different tables?
- Anonymous1 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.
I think hierarchies only work well in power bi if the levels are in the same table. Could you bring Story and Subtask keys into the Hours table using calculated columns -eg Story Key= related('Stories'[story Key] and build the hierarchy in the Hours table?
How would you identify the hierarchy if all the data is in the same table? You can't make a relationship within a single table. How would the the correct Sub-Task show under the correct parent if I'm only using keys from the Time Spent Table?