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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Josué
Frequent Visitor

Média condicional

Olá,

Sou novato com medidas DAX e estou com dificuldade para solucionar um problema. Preciso obter as médias de preços dos produtos. Porém o cálculo deve considerar apenas os produtos que possuem dados em todos os anos selecionados. Por exemplo o cód A tem dados em 2018, 2019 e 2020, o código B em 2018 e 2019, nesse caso a média deve ser apenas do código A. Caso seja segmentado apenas os anos de 2018 e 2019 então o código B pode ser calculado. Parece simples, porém com meus conhecimentos não sou capaz de encontrar uma fórmula que faça isso. Segue exemplo da tabela:

Captura de tela 2022-05-24 094542.png

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

Hi @Josué ,

 

Please try the following formula:

 

Measure = 
IF (
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Year] ), ALLSELECTED ( 'Table' ) )
        = DISTINCTCOUNT ( 'Table'[Year] ),
    AVERAGE ( 'Table'[Value] )
)

vkkfmsft_0-1653639293865.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
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
v-kkf-msft
Community Support
Community Support

Hi @Josué ,

 

Please try the following formula:

 

Measure = 
IF (
    CALCULATE ( DISTINCTCOUNT ( 'Table'[Year] ), ALLSELECTED ( 'Table' ) )
        = DISTINCTCOUNT ( 'Table'[Year] ),
    AVERAGE ( 'Table'[Value] )
)

vkkfmsft_0-1653639293865.png

 

If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
Best Regards,
Winniz
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@Josué , Try like

AverageX(Summarize(Table, Table[Year], Table[Product], "_1", Sum(Table[Price])),[_1])

 

or

 

calculate(AverageX(Summarize(Table, Table[Year], Table[Product], "_1", Sum(Table[Price])),[_1]), allexcept(Table, Table[Product])

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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.