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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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.
v-kongfanf-msft
Community Support
Community Support

Hi @Fabi ,

 

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

 

Best Regards,
Adamk Kong

Hi @v-kongfanf-msft ,
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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.