Forum Discussion
Help with changing specific row values in a matrix
- 1 year ago
Hi Maria_Maya ,
To apply a different calculation for just those two specific rows, you can modify your measure to check the current row's name and apply the correct logic accordingly.
You can replace your existing Resultado% measure with the updated DAX formula below. It incorporates your specific requirements while keeping the rest of your logic intact.
Resultado% = VAR CurrentJerarquia1 = SELECTEDVALUE('OrdenPyG'[Nombre Grupo]) VAR CurrentJerarquia2 = SELECTEDVALUE('Maximo-Balance'[JERARQUIA 2]) -- This is the main logic that will check which level of the hierarchy is active RETURN IF( ISINSCOPE('Maximo-Balance'[JERARQUIA 2]), // -- Calculations for Level 2 (JERARQUIA 2) -- VAR CurrentValue = SUM('Maximo-Balance'[Saldo]) // -- Calculate the specific revenues needed for the new logic. // -- We use ALLSELECTED to remove the filter from the current row and find the 'Ventas' rows. VAR VentasBar = CALCULATE( SUM('Maximo-Balance'[Saldo]), FILTER( ALLSELECTED('Maximo-Balance'), 'Maximo-Balance'[JERARQUIA 2] = "Ventas Serv Bar" ) ) VAR VentasRestaurante = CALCULATE( SUM('Maximo-Balance'[Saldo]), FILTER( ALLSELECTED('Maximo-Balance'), 'Maximo-Balance'[JERARQUIA 2] = "Ventas Serv Restaurante" ) ) // -- This is your original calculation for the total, used as the default. VAR TotalIngresosOperacionales = CALCULATE( SUM('Maximo-Balance'[Saldo]), FILTER( ALL('Maximo-Balance'), 'Maximo-Balance'[JERARQUIA 1] = "1 Ingresos Operacionales" ), KEEPFILTERS(VALUES(Calendario[Date])) ) // -- Use SWITCH to apply the correct formula for each row. RETURN SWITCH( TRUE(), CurrentJerarquia2 = "Costo Serv Bar", DIVIDE(CurrentValue, ABS(VentasBar)), CurrentJerarquia2 = "Costo Serv Restaurante", DIVIDE(CurrentValue, ABS(VentasRestaurante)), // -- Default calculation for all other rows in JERARQUIA 2 DIVIDE(CurrentValue, TotalIngresosOperacionales) ), // -- Calculations for Level 1 (JERARQUIA 1) - Your original SWITCH logic -- IF( HASONEVALUE(OrdenPyG[Nombre Grupo]), SWITCH( CurrentJerarquia1, "(+) Ingresos Operacionales", 1, "(-) Costos de Materias Primas", [12_Costo de Materia Prima], "⩧ Utilidad Bruta por MP", [13_Utilidad Bruta por MP], "(-) Costo de Produccion", [14_Costo de Producción], "⩧ Utilidad Bruta", [15_Utilidad Bruta], "(-) Gastos de Administración", [16_Gastos de Administracion], "(-) Gastos de Ventas", [17_Gastos de Ventas], "⩧ Utilidad Operacional", [18_Utilidad Operacional], "(+) Ingresos no Operacionales", [19_Ingresos No Operacionales], "(-) Gastos no Operacionales", [20_Gastos No Operacionales], "⩧ Utilidad Neta ", [21_Utilidad Neta] ) ) )This updated formula first checks if your matrix is expanded to the JERARQUIA 2 level using ISINSCOPE. If it is, it calculates the specific revenue values for the bar and restaurant using variables. The key part of these calculations is FILTER(ALLSELECTED('Maximo-Balance'), ...) which allows DAX to find the 'Ventas' (Sales) value that corresponds to the 'Costo' (Cost) row within the same period. A SWITCH(TRUE(), ...) statement then directs the calculation: if the row is "Costo Serv Bar" or "Costo Serv Restaurante", it performs your custom division. For all other rows at this level, it uses your original default calculation. I've also wrapped the revenue variables in the ABS function because your revenue figures are negative; this ensures the resulting cost percentage is a positive value, as is standard. The rest of the formula remains your original logic for the higher levels of your report.
Best regards,
Hi Maria_Maya,
As we haven’t heard back from you, so just following up to our previous message. I'd like to confirm if you've successfully resolved this issue or if you need further help.
If yes, you are welcome to share your workaround so that other users can benefit as well. And if you're still looking for guidance, feel free to give us an update, we’re here for you.
Best Regards,
Hammad.
Hi Maria_Maya,
Hope everything’s going smoothly on your end. As we haven’t heard back from you, so I wanted to check if the issue got sorted.
Still stuck? No worries just drop us a message and we can jump back in on the issue.
Best Regards,
Hammad.
- Anonymous1 year agoNot applicable
Hi Maria_Maya,
We noticed there hasn’t been any recent activity on this thread. If you still need support, just drop a reply here and we’ll pick it up from where we left off.Best Regards,
Hammad.