Forum Discussion

marakud's avatar
marakud
Frequent Visitor
3 years ago
Solved

DAX : SUM is wrong in matrix

Hi everyone,

 

I need your help for a calculation.

I make this :

 

Sales =
VAR _SALES = CALCULATE ( SUM ( 'Ca Réalisé'[Sales] ) )

VAR _SALES_NOPROD =
    CALCULATE (
        SUM ( 'Ca Réalisé'[Sales] ),
        T_DIM_PLAN2_NIV3[P2_NIV3_LIBELLE] <> "PROD SEULEMENT"
    )
   
RETURN
    IF (
    ISFILTERED ( Etablissement[Name] ),
    _SALES_NOPROD ,
    _SALES
    )
 
In VAR _SALES, i need to have this value "PROD SEULEMENT" in my total.

This measure works fine when it's display in a card.
But in my matrix (by Etablissement[Name]) , totals are wrong for VAR _SALES (all values).
When the slicer is not filtered, total show VAR _SALES_NOPROD results. 
 
 
what's wrong ?
 
thanks a lot

6 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi marakud ,

    It seems like you are trying to calculate sales with a filter on a specific value. However, the total is not showing the correct value in the matrix. One possible reason for this could be that the filter context is not being applied correctly. You may want to try using the ALL function to remove the filter context from the calculation. Here is an example of how you could modify your measure:

    Sales =
    VAR _SALES = CALCULATE ( SUM ( 'Ca Réalisé'[Sales] ) )
    
    VAR _SALES_NOPROD =
        CALCULATE (
            SUM ( 'Ca Réalisé'[Sales] ),
            T_DIM_PLAN2_NIV3[P2_NIV3_LIBELLE] <> "PROD SEULEMENT"
        )
       
    RETURN
        IF (
        ISFILTERED ( Etablissement[Name] ),
        CALCULATE(_SALES_NOPROD, ALL(Etablissement[Name])),
        _SALES
        )

    This should remove the filter context from the calculation and give you the correct total in the matrix.

     

    How to Get Your Question Answered Quickly 

     

    If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

     

    Best Regards
    Community Support Team _ Rongtie

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • marakud's avatar
      marakud
      Frequent Visitor

      I have observed that the issue stems from the ISFILTERED function, which considers the subcategories of the hierarchy as filtered rows. As a result, it always performs the first calculation based on the condition.

    • marakud's avatar
      marakud
      Frequent Visitor

      for more information :
      When my slicer is on, i need the calculation to be filter.
      And when it's off, i need all values selected.
      But when slicer is inactive , "PROD SEULEMENT" value is not in my SUM.

       

      Best