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
powerbi2srm
Resolver II
Resolver II

Calcular medida de totales

Hola!

 

Necesito ayuda para crear una medida que me calcule totales de tal forma que cuando arrastre esa medida a una tabla no le afecten los filtros de cada fila.

 

Para explicarlo mejor os pongo un ejemplo. Una empresa vende dos productos (mesas y sillas) a dos consumidores: 

 

table1.jpg

Lo que busco es una medida que me calculase el total para cada producto (8 sillas vendidas y 3 mesas), independientemente de cuál sea la factura o el cliente:

 

table2.jpg

 

Muchas gracias!!

2 ACCEPTED SOLUTIONS

@powerbi2srm 

 

total unit by product measure =
  VAR __product = MAX('Table 2'[product])
  VAR __table = FILTER(ALL('Table 1'),[product] = __product)
RETURN
  SUMX(__table,[units by invoice])

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

@powerbi2srm El archivo PBIX se adjunta debajo de la firma

Measure = 
    VAR __Product = MAX('dim_product'[product_id])
    VAR __Table = FILTER(ALL('fact_sale_invoice'),[product_id] = __Product)
RETURN
    IF(SUM('fact_sale_invoice'[product_quantity])>0,SUMX(__Table,[product_quantity]),BLANK())

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

13 REPLIES 13
powerbi2srm
Resolver II
Resolver II

Muchas gracias @Greg_Deckler. Esto me sirvió para resolver el problema, sin embargo al trabajar con grandes cantidades de datos daba algunos errores de carga. Probé esta cosa que me funcionó perfecto. Lo pongo por aquí. Por si alguien tiene el mismo problema en un futuro:

 

total unit by product = 
VAR TblSummary = ADDCOLUMNS(
    VALUES(fact_sale_invoice[product_id]),
    "Total", CALCULATE(SUM(fact_Sale_invoice[product_quantity]),ALL(fact_sale_invoice),VALUES(fact_Sale_invoice[product_id]))
)
RETURN
    SUMX(TblSummary,[Total])

 

powerbi2srm
Resolver II
Resolver II

Sigue sin funcionar... No entiendo por qué @Greg_Deckler 

@powerbi2srm ¿Puede publicar su archivo PBIX o una muestra que replica el modelo de datos?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Sí, pero ¿cómo puedo pasarte el archivo? @Greg_Deckler 

@powerbi2srm Usa OneDrive o Google Drive o Box, cualquier servicio de carga de archivos.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@powerbi2srm El archivo PBIX se adjunta debajo de la firma

Measure = 
    VAR __Product = MAX('dim_product'[product_id])
    VAR __Table = FILTER(ALL('fact_sale_invoice'),[product_id] = __Product)
RETURN
    IF(SUM('fact_sale_invoice'[product_quantity])>0,SUMX(__Table,[product_quantity]),BLANK())

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Disculpa las molestias, pero ¿como tendría que hacer para filtrar esos datos por fecha a través de DAX? Es decir, por ejemplo:  esa medida para el mes de enero. Esto es lo que he intentado, pero no me lo reconoce:

Unidades_totales_enero = 
VAR __Product = MAX(dim_product[product_id])

VAR __Table =
FILTER(
    ALLEXCEPT(fact_sale_invoice_line, fact_sale_invoice_line[invoice_date_id]),
    [product_id] = __Product
)

var resultado =
IF(
    SUM(fact_sale_invoice_line[product_quantity])>0,
    CALCULATE(
        SUMX(__Table, fact_sale_invoice_line[product_quantity]),
        AND(
            fact_sale_invoice_line[invoice_date_id]>=20220201,
            fact_sale_invoice_line[invoice_date_id]<=20220228
        )
    ),
    BLANK()
)

return resultado

 

Perdón por las molestias, @Greg_Deckler , pero es que me urge.

@powerbi2srm Maybe:

Measure = 
    VAR __Product = MAX('dim_product'[product_id])
    VAR __Table = FILTER(ALL('fact_sale_invoice_line'),[product_id] = __Product && [invoice_date_id]>=20220201 && [invoice_date_id]<=20220228
        )
RETURN
    IF(SUM('fact_sale_invoice_line'[product_quantity])>0,SUMX(__Table,[product_quantity]),BLANK())


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Mil gracias!!!! 😀

Greg_Deckler
Super User
Super User

@powerbi2srm 

 

total unit by product column =
  VAR __product = [product]
  VAR __table = FILTER('Table'[product] = __product)
RETURN
  SUMX(__table,[units by invoice])

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Disculpa, @Greg_Deckler, las columnas de la tabla que puse pertenecen a distintas tablas relacionadas. Por lo que creo que tu solución no funciona... Necesito una medida que me calcule eso para poder arrastrarla a la visualización de tabla.

@powerbi2srm 

 

total unit by product measure =
  VAR __product = MAX('Table 2'[product])
  VAR __table = FILTER(ALL('Table 1'),[product] = __product)
RETURN
  SUMX(__table,[units by invoice])

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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!

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.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.