cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
powerbi2srm
Helper II
Helper 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])

 


@ 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!:
Mastering Power BI 2nd Edition

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())

 


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

13 REPLIES 13
powerbi2srm
Helper II
Helper 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
Helper II
Helper 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?


@ 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!:
Mastering Power BI 2nd Edition

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.


@ 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!:
Mastering Power BI 2nd Edition

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())

 


@ 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!:
Mastering Power BI 2nd Edition

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())

@ 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!:
Mastering Power BI 2nd Edition

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])

 


@ 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!:
Mastering Power BI 2nd Edition

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])

 


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Dev Camp Session 30

Ted's Dev Camp - January 26, 2023

This session will provide guidance and teach campers the skills required to build Power BI reports that support multiple languages.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.