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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
Vilmar
Resolver I
Resolver I

Quantidade que vendeu da unidade, mesmo vendendo o kit (componente)

Olá,

Vendo produto por unidade e por kit (componentes). Mas quero saber qual foi o total vendido por unidade.

 

Na imagem foi vendido:
4 camisas,
5 kits contendo 3 camisas
3 kits contento 2 camisas e 1 bermuda.

 

Quero calcular o total de camisas:

Total de camisas = 4 + (5 * 3) + (3 * 2)

Total de camisas= 4 + 15 + 6

Total de camisas= 25

 

PBIX aqui 

 

Sem título.png

2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

You don't need measures for this. A calculated column in the fVenda table is enough

 

 

Total Qty = 
var parentCode=LOOKUPVALUE(fComponentes[CodProduto],fComponentes[CodProduto],[CodProduto])
var subqty = COALESCE(CALCULATE(sum(fComponentes[Qtde_componente]),fComponentes[CodProduto]=parentCode),1)
return subqty*[Qtde_vendida]

 

View solution in original post

Anonymous
Not applicable

Hi @Vilmar ,

 

Generally, I don't create any relationship in this case.

vstephenmsft_0-1647935200232.png

 

Here's my solution.

1.Create a measure to get the Venda in table 'fComponentes'.

VendaInfComponentes =
CALCULATE (
    SUM ( fVenda[Qtde_vendida] ),
    FILTER ( 'fVenda', [CodProduto] = MAX ( 'fComponentes'[CodProduto] ) )
)

 

2.Create a measure to get the product.

Sum =
[VendaInfComponentes] * SUM ( 'fComponentes'[Qtde_componente] )

vstephenmsft_1-1647935479110.png

 

3.Create a measure to get the Venda in table 'dProduto'.

VendaIndProduto =
CALCULATE (
    SUM ( fVenda[Qtde_vendida] ),
    FILTER ( 'fVenda', [CodProduto] = MAX ( 'dProduto'[CodProduto] ) )
)

 

4.Create a measure to call the [SUM] meausre in table 'fComponentes' into table 'dProduto'.

Sum2 =
SUMX (
    FILTER (
        ALLSELECTED ( 'fComponentes' ),
        [Cod_Componente] = MAX ( 'dProduto'[CodProduto] )
    ),
    [Sum]
)

 

vstephenmsft_2-1647935628077.png

 

5.Now you can add them up to get the total.

Total Venda = [Sum2]+[VendaIndProduto]

vstephenmsft_3-1647935669585.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Vilmar ,

 

Generally, I don't create any relationship in this case.

vstephenmsft_0-1647935200232.png

 

Here's my solution.

1.Create a measure to get the Venda in table 'fComponentes'.

VendaInfComponentes =
CALCULATE (
    SUM ( fVenda[Qtde_vendida] ),
    FILTER ( 'fVenda', [CodProduto] = MAX ( 'fComponentes'[CodProduto] ) )
)

 

2.Create a measure to get the product.

Sum =
[VendaInfComponentes] * SUM ( 'fComponentes'[Qtde_componente] )

vstephenmsft_1-1647935479110.png

 

3.Create a measure to get the Venda in table 'dProduto'.

VendaIndProduto =
CALCULATE (
    SUM ( fVenda[Qtde_vendida] ),
    FILTER ( 'fVenda', [CodProduto] = MAX ( 'dProduto'[CodProduto] ) )
)

 

4.Create a measure to call the [SUM] meausre in table 'fComponentes' into table 'dProduto'.

Sum2 =
SUMX (
    FILTER (
        ALLSELECTED ( 'fComponentes' ),
        [Cod_Componente] = MAX ( 'dProduto'[CodProduto] )
    ),
    [Sum]
)

 

vstephenmsft_2-1647935628077.png

 

5.Now you can add them up to get the total.

Total Venda = [Sum2]+[VendaIndProduto]

vstephenmsft_3-1647935669585.png

 

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

lbendlin
Super User
Super User

You don't need measures for this. A calculated column in the fVenda table is enough

 

 

Total Qty = 
var parentCode=LOOKUPVALUE(fComponentes[CodProduto],fComponentes[CodProduto],[CodProduto])
var subqty = COALESCE(CALCULATE(sum(fComponentes[Qtde_componente]),fComponentes[CodProduto]=parentCode),1)
return subqty*[Qtde_vendida]

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

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