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
dvhez
Helper II
Helper II

Average by category AND date

I'd like to calculate the average of CMg for every Bloque Horario category (A, B and C). I tried with the following measure which works only if select one month. However, my data has 10 years with 12 months each one:

 

AverageMeasure =
CALCULATE (
    AVERAGE ( Data[CMg] ),
    FILTER ( ALLSELECTED ( Data ), Data[Bloque Horario] = MAX ( Data[Bloque Horario] ) )
)

 

PBIDesktop_2019-05-02_21-22-27.png

 

 

 

 

1 ACCEPTED SOLUTION
MariaP
Solution Supplier
Solution Supplier

Hi @dvhez ,

From your comment: calculate only the block (A, B or C) corresponding to each month and year?

It now sounds like you do not need  the Year|Month|Hour  to average by but Year|Month ?

Is this the result you are after?


Jan 2019[ A] = 44.03 , Jan 2019 [B] = 43.0Jan 2019[ A] = 44.03 , Jan 2019 [B] = 43.0
Feb 2019 [A] = 45.62 , Feb 2019 [B] = 44.59Feb 2019 [A] = 45.62 , Feb 2019 [B] = 44.59

If so here is the code for this one. Note, filter context is crucial when using these calculations

_Measure5 = 
CALCULATE (
    AVERAGE(Data[CMg] ),
    FILTER ( ALL( Data ), Data[Bloque Horario] <= MAX ( Data[Bloque Horario] )  && Data[Date] <= MAX(Data[Date])
))

 

View solution in original post

13 REPLIES 13

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.