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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Fabi
Frequent Visitor

AVERAGEX, SUMMARIZE, 0 for no data

Hi all !
I have several conditions to respect in my calculation: for a station, I must count the number of activities (type 1, 2 or 3 only) that took place on three different services (DAY, NIGHT and MIXED) per month. When two or more activities took place on my station during the month for a service, the value must be 1, if there was only one activity then the value must be 0.5, if zero, 0.
I then need to average this calculation.

 

I created several measures that allow me to almost achieve the expected result:
The first calculates the number of activities according to type:

 

NumberActivities =
CALCULATE (
DISTINCTCOUNT(Data[ID_Act]),
Data[Type_Act] IN {"1", "2", "3"}
)​

 

The second assigns the desired value 1, 0.5 or 0 :

 

ValueActivities =
SWITCH(
TRUE(),
[NumberActivities] = 0, 0,
[NumberActivities] = 1, 0.5,
[NumberActivities] >= 2, 1
)

 

The third which poses a problem for me calculates the average according to the month/year, station and service conditions:

 

AvgValues =
AVERAGEX(
SUMMARIZE(
'Data',
'Data'[Station],
Data[Sevice],
Data[Month/Year],
"Valeur",
[ValueActivities]
),
[Valeur]
)

 

In fact, this calculation does not take into account the 0 in the average when there is no data for the service. 

In the following example, for station S1 in march 2024 the average should be 0.66

Fabi_2-1718030880690.png
In this one, in april 2024, the average is good because it takes into account 0 for the MIXED, because there was indeed an activity even if it is not of type 1, 2 or 3 (4 here) :
Fabi_3-1718031245881.png

 

How can I have 0.66 for the first exemple ?

Thank you all. 
 
My datas : 
ID_ActSeviceDateStationType_ActMonth/Year
A1DAY01/03/2024S1132024
A2NIGHT02/03/2024S1132024
A3NIGHT04/03/2024S1232024
A4DAY06/03/2024S1232024
A5DAY06/04/2024S1342024
A6NIGHT04/04/2024S1342024
A7MIXED02/04/2024S1442024
A8MIXED01/04/2024S1442024
A9DAY01/03/2024S2132024
A10DAY02/03/2024S2232024
A11NIGHT04/03/2024S2332024
A12NIGHT06/03/2024S2432024
A13NIGHT12/03/2024S2332024
A14NIGHT11/03/2024S2232024
A15MIXED10/03/2024S2132024
A16MIXED09/03/2024S2232024

3 REPLIES 3
Fabi
Frequent Visitor

I found the solution:
I divided the last measurement into 3 different measurements, one for night, one for day and the last for mixed.
Like this :

AvgValueNight = AVERAGEX(
   SUMMARIZE(
       'data',
       data[Station],
        data[Month/Year],
       "Valeur",
       CALCULATE([ValeurActivities], data[Service] = "NIGHT")
   ),
   [Valeur]
)

So, I have a 0 if there is no value for the service.


I then made a measurement for the overall:

([AvgValueNight]+[AvgValueDay]+[AvgValueMixed])/3

This works because we only have 3 values ​​for the service and we do not put "Services" filters on our report page.
If this were not the case, another solution would have to be found.
Anonymous
Not applicable

Hi @Fabi ,

 

[Month/Year] This field does not seem to match the test data you provided.

 

Best Regards,
Adamk Kong

Hi @Anonymous ,
Indeed, it is a column that I had calculated in my report. I just added it to the table from my previous post. Thanks !
 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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