Forum Discussion
Calculate Custom Row Subtotal in Matrix Visual
- Anonymous2 years ago
Hi ZiyadSyauqi ,
Thanks for the reply from ridhoaryo24 / amitchandak .
Please try:
Enter Power Query and pivot the Attribute column:
This is the data after pivoting:
Exit Power Query and create a measure:
Measure = VAR _tm = SUM('Table'[tm_actual]) VAR _lm = SUM('Table'[lm_actual]) RETURN IF( HASONEVALUE('Table'[group_metrics]), DIVIDE(SUM('Table'[tm_actual]),SUM('Table'[lm_actual])), DIVIDE(_tm,_lm))After creation, set the format:
Drag the following fields to the Matrix visual object:
The final page effect is as follows:
If you have any other questions please feel free to contact me.
The pbix file is attached.
Best Regards,
Yang
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot! - 2 years ago
Thanks using some additional DAX code and combine with your solution i got this solution:
ValueNew = VAR lm_actual = CALCULATE( SUM(Table[Value]), Table[Attribute] = "lm_actual", ALLEXCEPT(Table, Table[group_metrics], Table[metrics]) ) VAR tm_actual = CALCULATE( SUM(Table[Value]), Table[Attribute] = "tm_actual", ALLEXCEPT(Table, Table[group_metrics], Table[metrics]) ) VAR lm_group = CALCULATE( SUM(Table[Value]), Table[Attribute] = "lm_actual", ALLEXCEPT(Table, Table[group_metrics]) ) VAR tm_group = CALCULATE( SUM(Table[Value]), Table[Attribute] = "tm_actual", ALLEXCEPT(Table, Table[group_metrics]) ) RETURN SWITCH( TRUE(), SELECTEDVALUE(Table[Attribute]) = "vs_n_min_1_pct" && HASONEVALUE(Table[metrics]), DIVIDE(tm_actual, lm_actual, 0), SELECTEDVALUE(Table[Attribute]) = "vs_n_min_1_pct" && NOT HASONEVALUE(Table[metrics]), DIVIDE(tm_group, lm_group, 0), SUM(Table[Value]) )
Hi Ziyad,
You can make these measure to get the result you want
lm_actual = CALCULATE(SUM('Sheet1 (2)'[Value]), FILTER('Sheet1 (2)', 'Sheet1 (2)'[Attribute]="lm_actual"))
tm_actual = CALCULATE(SUM('Sheet1 (2)'[Value]), FILTER('Sheet1 (2)', 'Sheet1 (2)'[Attribute]="tm_actual"))
And then, you make this measure:
vs_n_min_1_pct =
VAR lm_group = CALCULATE(
[meas_lm_actual],
ALLEXCEPT('Sheet1 (2)', 'Sheet1 (2)'[group_metrics])
)
VAR tm_group = CALCULATE(
[meas_tm_actual],
ALLEXCEPT('Sheet1 (2)', 'Sheet1 (2)'[group_metrics])
)
Add those calculations to the Values accordingly.
There is no need to insert anything in the Columns.
May it help you.
Regards,
Ridho A.
Thanks using some additional DAX code and combine with your solution i got this solution:
ValueNew =
VAR lm_actual = CALCULATE(
SUM(Table[Value]),
Table[Attribute] = "lm_actual",
ALLEXCEPT(Table, Table[group_metrics], Table[metrics])
)
VAR tm_actual = CALCULATE(
SUM(Table[Value]),
Table[Attribute] = "tm_actual",
ALLEXCEPT(Table, Table[group_metrics], Table[metrics])
)
VAR lm_group = CALCULATE(
SUM(Table[Value]),
Table[Attribute] = "lm_actual",
ALLEXCEPT(Table, Table[group_metrics])
)
VAR tm_group = CALCULATE(
SUM(Table[Value]),
Table[Attribute] = "tm_actual",
ALLEXCEPT(Table, Table[group_metrics])
)
RETURN
SWITCH(
TRUE(),
SELECTEDVALUE(Table[Attribute]) = "vs_n_min_1_pct" && HASONEVALUE(Table[metrics]),
DIVIDE(tm_actual, lm_actual, 0),
SELECTEDVALUE(Table[Attribute]) = "vs_n_min_1_pct" && NOT HASONEVALUE(Table[metrics]),
DIVIDE(tm_group, lm_group, 0),
SUM(Table[Value])
)