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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
brucruz
Frequent Visitor

How can I calculate the average price from the previous day, filtering by groups?

I have been trying to perfom a dax calculation without success. My objective is to obtain the average of the column [Média de Preco] considering some filters, which I was able to do with the code bellow.

pbi_issue1.JPG

 

MediaPB_Band_AI_Dia = 
CALCULATE(
    dPBomba_AI_FL[.PBomba_Medio];
    ALLEXCEPT(dPBomba_AI_FL;
        dPBomba_AI_FL[Data Coleta];
        dPBomba_AI_FL[Área de Influência];
        dPBomba_AI_FL[Combustivel];
        dPBomba_AI_FL[Bandeira]
    )
)

The problem is that I need to also calculate for each row the same expression considering the previous day. That means: to obtain the average price of a set of filters, but filtering not the day expressed in the same row, but the equivalent of the previous day.

I have already tried some codes, without sucess, like:

 

∆PBMedio%_Dia = 
CALCULATE(
    AVERAGE(dPBomba_AI_FL[Média de Preco]);
    dPBomba_AI_FL[Data Coleta]-1;
    ALLEXCEPT(
        dPBomba_AI_FL;
        dPBomba_AI_FL[Área de Influência];
        dPBomba_AI_FL[Combustivel];
        dPBomba_AI_FL[Bandeira]
    )
)

Could you please help me accomplish this?

Thank you,

Bruno

1 REPLY 1
v-juanli-msft
Community Support
Community Support

Hi @brucruz 

Is my understanding correct?

If not, use my example to illustrate your expected result.

Área de Influência Combustivel Bandeira .PBomba_Medio Data Coleta sum average rule
a b c 1 10/2/2018 1+2 (3/1) (=sum/days)
a b c 2 10/2/2018 1+2 (3/1)  
a b c 3 10/3/2018 1+2+3 (6/2)  
a b c 4 10/4/2018 3+4 (7/2)  
a b c 5 10/5/2018 4+5 (9/2)  

 

Best Regards
Maggie

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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