Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Macesa
Regular Visitor

CALCULAR SUBTOTALES EN UNA MATRIZ

 

Hola buen día colegas. Quizás me pueden ayudar con lo siguiente:

 

Tengo una matriz en Power BI que tiene el campo Municipio en ROW y en Values tiene tres campos: 1.-  Personas, 2.-  % que es una medida del % de personas sobre el total y 3.- Color que es otra medida que se calcula de acuerdo a la Medida % ( Mayor o igual a 9% pintar la fila en RED, de 5 a 8.99 en YELLOW y menor a 5 GREEN.

 

Ahora necesito tener los subtotales por cada grupo de color y obtener un acumulado de %. La tabla final debe verse así:

 

Captura.JPG

¿ Alguien que me pueda ayudar a concretizar esta solicitud?

 

Gracias

 

 

 

1 ACCEPTED SOLUTION
v-kelly-msft
Community Support
Community Support

Hi @Macesa ,

 

I'll show you a workaround to do it:

First create a table such as below:

Annotation 2020-03-09 150849.png

Putting all the fields of column "Municipio" with nu3 rows of "subtotal" in it ,adding an index column in query editor,then modify your measure as below:

 

Measure 2 = 
IF (
    ISINSCOPE ( 'Table (3)'[Column1] ),
    IF (
        FIND ( "total", SELECTEDVALUE ( 'Table (3)'[Column1] ), 1, -1 ) > 0,
        VAR currentTotalIndex =
            MIN ( 'Table (3)'[Index] )
        VAR lastTotalIndex =
            CALCULATE (
                MAX ( 'Table (3)'[Index] ),
                FILTER (
                    ALLSELECTED ( 'Table (3)' ),
                    'Table (3)'[Index] < currentTotalIndex
                        && FIND ( "total", [Column1], 1, -1 ) > 0
                )
            ) + 0
        RETURN
            CALCULATE (
                SUM ( 'Table (3)'[value] ),
                FILTER (
                    ALLSELECTED ( 'Table (3)' ),
                    'Table (3)'[Index] > lastTotalIndex
                        && 'Table (3)'[Index] < currentTotalIndex
                )
            ),
        SUM ( 'Table (3)'[value] )
    ),
    CALCULATE (
        SUM ( 'Table (3)'[value] ),
        FILTER ( 'Table (3)', FIND ( "total", [Column1], 1, -1 ) = -1 )
    )
)

 

Finally you will see:

Annotation 2020-03-09 160417.png

Here is the related .pbix file.

 

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

y cómo se podría hacer para tener una fila de año total y TDY debajo,

tornikevadach_0-1712828387414.png

 

Necesito debajo del total para agregar el total YTD, no sé cómo poner los totales en fila, debajo de cada columna su respectivo total YTD ni cómo calcular el YTD.

v-kelly-msft
Community Support
Community Support

Hi @Macesa ,

 

I'll show you a workaround to do it:

First create a table such as below:

Annotation 2020-03-09 150849.png

Putting all the fields of column "Municipio" with nu3 rows of "subtotal" in it ,adding an index column in query editor,then modify your measure as below:

 

Measure 2 = 
IF (
    ISINSCOPE ( 'Table (3)'[Column1] ),
    IF (
        FIND ( "total", SELECTEDVALUE ( 'Table (3)'[Column1] ), 1, -1 ) > 0,
        VAR currentTotalIndex =
            MIN ( 'Table (3)'[Index] )
        VAR lastTotalIndex =
            CALCULATE (
                MAX ( 'Table (3)'[Index] ),
                FILTER (
                    ALLSELECTED ( 'Table (3)' ),
                    'Table (3)'[Index] < currentTotalIndex
                        && FIND ( "total", [Column1], 1, -1 ) > 0
                )
            ) + 0
        RETURN
            CALCULATE (
                SUM ( 'Table (3)'[value] ),
                FILTER (
                    ALLSELECTED ( 'Table (3)' ),
                    'Table (3)'[Index] > lastTotalIndex
                        && 'Table (3)'[Index] < currentTotalIndex
                )
            ),
        SUM ( 'Table (3)'[value] )
    ),
    CALCULATE (
        SUM ( 'Table (3)'[value] ),
        FILTER ( 'Table (3)', FIND ( "total", [Column1], 1, -1 ) = -1 )
    )
)

 

Finally you will see:

Annotation 2020-03-09 160417.png

Here is the related .pbix file.

 

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

 

amitchandak
Super User
Super User

In Quick measure, you have an option for running total, create a running total using that, Say Cumm

https://www.edureka.co/community/41446/how-to-calculate-cumulative-total-and-in-dax

 

Create GT Like

Calculate(sum(Table[Personas]),all(Table))

% of Cumm = [Cumm]/GT

https://www.c-sharpcorner.com/article/calculate-cumulativerunning-total-in-power-bi/

 

Create a color measure.

color =
var _change =[% of Cumm]
return
SWITCH (
TRUE(),
_change > 80, "green",
_change > 38, "yellow",
"red"
)

 

No go to conditional formatting or background color of the field and DO it for each field. Go to advance control and select field and choose this measure.

https://docs.microsoft.com/en-us/power-bi/desktop-conditional-table-formatting#color-by-color-values

 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

 

Hola, la matriz está completada con las medidas de colores.

 

Ahora lo que quiero hacer es calcular los subtotales para cada rango de color ya que no he encotrando forma de hacerlo en power bi.

 

Así se mira actualmente la matriz.

 

Captura2.JPG

As of now, I have no Idea about how color is working, but a measure like should give a total of color

red = calculate(sum(table[persona]), values(table[MUNICIPO]),filter(table, [Cumm%]<=.38))
or
sumx(filter(summarize(table,table[MUNICIPO],"_cumm",[Cumm%],"_per",sum(table[persona])),[_cumm]<=.38),[_per])

green= calculate(sum(table[persona]),values(table[MUNICIPO]), filter(table, [Cumm%]>=.78))

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@Macesa , I am not sure, If the last update help you or you need more info.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.