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
pfroide
Frequent Visitor

Differents ways to calculte total with measure

Hi,

I'm new in PowerBI so maybe my question is not very clear. If so, please tell me and I'll try to be more explicit.

I've created a Measure and its behavoir seems different in two tables. It is called "Moyennes heure supplémentaires". In this first picture, you can see that the total is the mean of all valeus, that's correct and that's the behavior I want.

Edit : I juste saw it's not the mean, it's something else but I don't know what (mean(14,93 + 9,5 + 13,06 + 9,81 + 8,13 + 5,31 + 6,92 + 8,63 + 9,08) = 9,45 <> 9,61)

1.png

In this second, the behavior is different, and the total is a sum of the values.

Edit : I juste saw it's not the sum, it's something else but I don't know what (18,43 + 13,27 + 12,31 + 13,22 = 57,23 <> 54)

2.png

Why is this happening ? And mot importanty, how can I tell the behavior I want for a measure ?

The measure is composed by other mesure, as you can see :

moyenne_heures_supp = 
IFERROR ( CALCULATE ( [temps_heures_supp] / [effectif_reel] ); BLANK () )

Thanks in advance for your help.

8 REPLIES 8
pfroide
Frequent Visitor

Hey,

 

I succeded to do what I wanted by using the formula HASONEFILTER.

 

WIth this function I can have two different formulas : one for the rows with filter, and another one for the total row.

 

Thanks for your help !

Anonymous
Not applicable

@pfroide  - What are the formulas for:

[temps_heures_supp]
and
[effectif_reel]

Hi,

 

There are the two formulas, based on measures too :

temps_heures_supp = CALCULATE([total_temps_travaille_1]-[temps_standard_travaille])
effectif_reel = CALCULATE([effectif_theorique] - [effectif_maternite] - [effectif_maladie])

And maybe you will need these too :

total_temps_travaille_1 = CALCULATE([temps_chargeable]+[temps_nonchargeable])
temps_chargeable = 
VAR calcul =
    CALCULATE (
        SUM ( lignes_temps_services[nb_heures] );
         OR (
            lignes_temps_services[id_projet] < 1107;
            lignes_temps_services[id_projet] > 1116
        )
    )
RETURN
    IF ( calcul > 0; calcul; 0 )
temps_nonchargeable = 
CALCULATE (
    [tps_projet] + [tps_administration] + [tps_disponibilite] + [tps_maladie] + [tps_cp_exc] + [tps_marketing] + [tps_formations]
)
tps_administration = 
VAR calcul =
    CALCULATE (
        SUM ( lignes_temps_services[nb_heures] );
        lignes_temps_services[id_projet] = 1109
    )
RETURN
    IF ( calcul > 0; calcul; 0 )

This last one is very similar to all the ones that allow me to calculte temps_nonchargeable, only the id changes

Maybe you need all of them ?

Thanks.

 

I saw this strange behavior too.

 

The total for 'effectif_reel' and 'moyenne_heures_supp" don't change as I except them to do when a filter with the month is checked.

With all months on :3.png

 

When I unchek May and June :

 

4.png

 

There is definitely something wrong with them !

Anonymous
Not applicable

@pfroide  - I think you should troubleshoot all of the measures that these measures depend on, and see where it goes wrong.

I think my measures are good because all values are correct. Only the "total" are not.

Anonymous
Not applicable

@pfroide - The "Total" behavior depends on the expressions - so if the Total is wrong, the measure is wrong. What you need to figure out is when it goes wrong. 

 

DAX works by applying the relevant filters to the calculation. One potential issue with your measures is the logic that sets it to zero if it's not greater than zero. This could eliminate negative values for particular data points, but the negative values would actually be incorporated into the total.

 

Hope this helps,

Nathan

Anonymous
Not applicable

It would also be helpful to see the various measures in the visualization - the measure is question is a straight division (it would be preferable to use the DIVIDE function, but it should work the way it is). So check the values of the numerator and denominator for each row - I think that the math should work.

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.