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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
grgilardi
Frequent Visitor

Configuración de Líneas de Comparación en Matriz"

Hola,

Quisiera solicitar su apoyo para que me guíen en cómo agregar una línea adicional en la matriz de Power BI que se llame "Costa Comparable." Esta línea debería mostrar la suma de todos los puntos de venta (PDVs) dentro de la zona "Costa," excluyendo el PDV "DOM." La línea "Costa Total" debería mantenerse como el total de todos los PDVs en la zona Costa.

Además, necesitaría un total adicional que incluya el PDV "DOM" y otro que lo excluya, siendo este último llamado "Total Comparable."

Es importante mencionar que la clasificación de zonas proviene de una dimensión en la que los PDVs están agrupados por zona. Adjunto algunas imágenes para ilustrar cómo me gustaría que se vea el resultado en la matriz.

Agradezco mucho cualquier sugerencia o ajuste que me puedan brindar para implementar estas líneas en Power BI.

1111.png

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

Hi @grgilardi ,

 

I've made a test for your reference:

1\I assume there is a table

vbofengmsft_0-1730857998381.png

2\Power Query

let
    Source = Excel.Workbook(File.Contents("C:\Users\Bof\Desktop\Book1106.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"sucursal_id", Int64.Type}, {"zona", type text}, {"sucursal_abrev", type text}, {"value", Int64.Type}}),
    // Filter out rows where sucursal_abrev is "DOM"
    FilteredRows = Table.SelectRows(#"Changed Type", each [sucursal_abrev] <> "DOM"),
    // Group by "zona" and calculate the sum of "value"
    GroupedSummary = Table.Group(
        FilteredRows, 
        {"zona"}, 
        {{"value", each List.Sum([value]), type number},{"sucursal_abrev",each List.First([zona]) & " COMPARABLE" , type text }}
    ),
    // Calculate the overall total for all non-DOM values
    OverallTotalValue = List.Sum(FilteredRows[value]),
   // Create an overall total row
    OverallTotalRow = Table.FromRecords({
        [sucursal_abrev = "TOTAL COMPARABLE", value = OverallTotalValue,zona="TOTAL COMPARABLE"]
    }),
   // Combine the original table with the summary table
    CombinedTable = Table.Combine({#"Changed Type", GroupedSummary,OverallTotalRow}),
    #"Changed Type1" = Table.TransformColumnTypes(CombinedTable,{{"value", type number}})
    
in
    #"Changed Type1"

vbofengmsft_1-1730858053366.png

3\Add a measure

Custom Total = 
If(ISINSCOPE(Sheet1[sucursal_abrev])||SELECTEDVALUE(Sheet1[zona])="TOTAL COMPARABLE",SUM(Sheet1[value]),CALCULATE(SUM(Sheet1[value]),NOT(ISBLANK(Sheet1[sucursal_id]))))

4\Add a matric visual

vbofengmsft_2-1730858132747.png

 

Best Regards,

Bof

 

 

View solution in original post

2 REPLIES 2
v-bofeng-msft
Community Support
Community Support

Hi @grgilardi ,

 

I've made a test for your reference:

1\I assume there is a table

vbofengmsft_0-1730857998381.png

2\Power Query

let
    Source = Excel.Workbook(File.Contents("C:\Users\Bof\Desktop\Book1106.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"sucursal_id", Int64.Type}, {"zona", type text}, {"sucursal_abrev", type text}, {"value", Int64.Type}}),
    // Filter out rows where sucursal_abrev is "DOM"
    FilteredRows = Table.SelectRows(#"Changed Type", each [sucursal_abrev] <> "DOM"),
    // Group by "zona" and calculate the sum of "value"
    GroupedSummary = Table.Group(
        FilteredRows, 
        {"zona"}, 
        {{"value", each List.Sum([value]), type number},{"sucursal_abrev",each List.First([zona]) & " COMPARABLE" , type text }}
    ),
    // Calculate the overall total for all non-DOM values
    OverallTotalValue = List.Sum(FilteredRows[value]),
   // Create an overall total row
    OverallTotalRow = Table.FromRecords({
        [sucursal_abrev = "TOTAL COMPARABLE", value = OverallTotalValue,zona="TOTAL COMPARABLE"]
    }),
   // Combine the original table with the summary table
    CombinedTable = Table.Combine({#"Changed Type", GroupedSummary,OverallTotalRow}),
    #"Changed Type1" = Table.TransformColumnTypes(CombinedTable,{{"value", type number}})
    
in
    #"Changed Type1"

vbofengmsft_1-1730858053366.png

3\Add a measure

Custom Total = 
If(ISINSCOPE(Sheet1[sucursal_abrev])||SELECTEDVALUE(Sheet1[zona])="TOTAL COMPARABLE",SUM(Sheet1[value]),CALCULATE(SUM(Sheet1[value]),NOT(ISBLANK(Sheet1[sucursal_id]))))

4\Add a matric visual

vbofengmsft_2-1730858132747.png

 

Best Regards,

Bof

 

 

lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).

Do not include sensitive information. Do not include anything that is unrelated to the issue or question.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...

Please show the expected outcome based on the sample data you provided.

Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.