Forum Discussion

Audrey_ADAPEI35's avatar
Audrey_ADAPEI35
Frequent Visitor
1 year ago
Solved

DAX calcul variations

Bonjour,

Je rencontre un problème qui semble facile à résoudre mais je n’arrive pas à trouver la formule magique…

Dans mon grand livre de compte, les charges apparaissent en négatif et les produits en positif. Quand je les analyse sur une matrice par année, tout s’affiche parfaitement côté solde etc. J’ai en // une table de dimension pour les comptes pour faire des regroupements : charges/produits, groupe…

 

Pour faire une variation entre deux années de mes soldes, j’ai utilisé en test la fonction “TEST123”

[1- Réel]-(CALCULATE([1- Réel],SAMEPERIODLASTYEAR('Table date'[Date])))

qui montre le résultat naturel de variation, mais il est “faux” sur la partie charges et total. Enfin, le sens est faux, ce qui n’est pas correcte pour l’analyse.

 

 

Même ligne à ligne, j’ai plein d’incohérences :

 

 

Est-ce que vous pourriez m’expliquer svp comment vous auriez procéder ? ou comment vous procédez actuellement?

6 Replies

  • Hi Audrey_ADAPEI35 ,

     

    Of course. This is a very common challenge when doing financial analysis in Power BI. Your DAX calculation isn't actually incorrect; it's mathematically sound. The issue you're facing is a matter of financial interpretation, where an increase in expenses is typically viewed as an unfavorable event. Your current formula, which calculates the difference between the current and prior year, is the standard method for measuring the direct impact on your net profit.

     

    Let's break down your results. Your expenses (Charges) increased from -10.9M€ to -11.2M€. The calculation (-11,249,124) - (-10,931,551) correctly yields -317,573 €. This negative result accurately represents the unfavorable impact on your bottom line. An increase in costs hurts profit. Likewise, when your revenue (Produits) decreases, the variance is also negative, as this is also an unfavorable event. Your total variance is therefore a coherent sum of all the favorable and unfavorable impacts.

     

    If you wish to change this so that an increase in expenses appears as a positive number (to show the magnitude of the increase rather than its impact on profit), you must logically reverse the sign of the variance for expense-related accounts only. You can achieve this by creating a new measure that identifies the account type from your dimension table. Assuming you have a column named [Account Type] in your accounts dimension table that specifies "Expenses" or "Revenue", you can use the following DAX logic.

    Adjusted Variance = 
    VAR RawVariance = [Actuals] - CALCULATE([Actuals], SAMEPERIODLASTYEAR('Date Table'[Date]))
    VAR AccountCategory = SELECTEDVALUE('Dim Accounts'[Account Type])
    RETURN
        IF(
            AccountCategory = "Expenses",
            -1 * RawVariance, -- Invert the sign for expenses
            RawVariance       -- Keep the original sign for revenue and other accounts
        )

    Be very careful with this approach. While it may seem more intuitive on the expense lines, it will make your Total line mathematically incorrect. The sum of the individual variances will no longer equal the variance on the Total line, because you will be adding inverted numbers to non-inverted ones. This can be very misleading.

     

    The most robust and recommended best practice is to keep your original formula and use conditional formatting to improve visual clarity. Your original calculation is superior because it is additive and consistently reflects the impact on profit from top to bottom. Instead of changing the DAX, go to the formatting options for your matrix in Power BI. Under "Cell elements," apply icons or background colors to your variance measure. For example, set a rule to show a green icon for any value greater than zero (a favorable variance) and a red icon for any value less than zero (an unfavorable variance). This method gives you the best of both worlds: a visually intuitive report and data that remains mathematically and analytically sound.

     

    Best regards,

    • Audrey_ADAPEI35's avatar
      Audrey_ADAPEI35
      Frequent Visitor

      Merci DataNinja777 pour votre réponse. Mais du coup, cela ne résoud pas trop mon problème. Par rapport aux matrices que j'ai, je ne peux pas me baser sur la formule originale. J'avais crée une formule DAX qui prenait en compte le type de compte "charges ou produits" mais dont le total est faux. J'avais masqué le total avec de la mise en forme conditionnelle. Pour le moment, je vais devoir garder cela.

       

      Je serai preneur d'un autre avis 🙂

  • v-venuppu's avatar
    v-venuppu
    Icon for Community Support rankCommunity Support

    Hi Audrey_ADAPEI35 ,

    I wanted to check if you had the opportunity to review the information provided and resolve the issue..?Please let us know if you need any further assistance.We are happy to help.

    Thank you.

  • v-venuppu's avatar
    v-venuppu
    Icon for Community Support rankCommunity Support

    Hi Audrey_ADAPEI35 ,

    May I ask if you have resolved this issue? Please let us know if you have any further issues, we are happy to help.

    Thank you.

  • v-venuppu's avatar
    v-venuppu
    Icon for Community Support rankCommunity Support

    Hi Audrey_ADAPEI35 ,

    I hope the information provided is helpful.I wanted to check whether you were able to resolve the issue with the provided solutions.Please let us know if you need any further assistance.

    Thank you.