DAX – Actual vs Budget variance, how to calculate when applying filter on same column

  • DAX – Actual vs Budget variance, how to calculate when applying filter on same column

    Posted by DSC Communities on January 12, 2020 at 4:29 pm
    • Stephane Gelinas

      Member

      January 12, 2020 at 4:29 PM

      Hello all,

      I am a DAX beginner and need help your help!Ā  Ā I am currently developing something in Excel (PowerPivot) and myĀ DAX formula that calculates a variance between budget and actual doesn’t work correctly when there is no value for an account, either at the “budget” or the “actuals”.

      I have a data table that contains the budget and expenses for condominium units.

      It is possible that for an account there is a value budgeted but we have no actuals (no line, e.g. a null value), and it is possible that there is an actual expense, but nothing was budgeted (again, no line).

      The data table (which I simplified for this example) looks like this :

      Year

      Scenario

      Account No

      Account Description

      Condo Unit

      Amount

      (Montant)

      2019

      Actual

      5100

      Electricity

      6835

      100

      2019

      Budget

      5100

      Electricity

      6835

      110

      2019

      Actual

      5200

      Maintenance

      6835

      50

      2019

      Budget

      5300

      Various expenses

      6835

      25

      Ā 

      I would like to calculate a variance, based on applied filter (e.g., slice the report per Condo Unit).

      The formula works when there is data in both actual and budgetĀ  (e.g., the first two lines in the example), but doesn’t work,Ā  or actually works occasionally, when either the actual or the budget has no value (example: the last 2 lines).

      This is the formula I used (it’s in French so slightly different from the simplified example) :

      Ecart:=CALCULATE(SUMX(DataTable, DataTable [Montant]), DataTable [ScĆ©nario]=”Budget”)-CALCULATE(SUMX(DataTable, DataTable [Montant]), DataTable [ScĆ©nario]=”RĆ©el”)

      Ā 

      Example of the report :

      Budget

      RƩel

      No Compte

      CatƩgorie

      Sous-catƩgorie

      Montant

      Montant

      Ecart

      1000

      Cotisation régulière

      Cotisation régulière

      9,974

      30,843

      -20,869

      Ā 

      Ā 

      Ā 

      9,974

      30,843

      -20,869

      5100

      Assurances

      Assurances

      12,035

      13,633

      -1,598

      5210

      Entretien du bâtiment

      Ventilation

      4,397

      -4,397

      5225

      Entretien du bâtiment

      Portes/fenĆŖtres et serrures

      1,209

      -1,209

      5240

      Entretien du bâtiment

      Luminaires

      25

      -25

      5260

      Entretien du bâtiment

      Articles saisonniers

      126

      -126

      5280

      Entretien du bâtiment

      Divers

      2,000

      5310

      DƩneigement

      Stationnements

      794

      830

      -36

      5320

      DƩneigement

      EntrƩes avant

      641

      670

      -29

      5330

      DƩneigement

      Escaliers

      1,321

      1,381

      -60

      5340

      DƩneigement

      Cours commune

      263

      275

      -12

      5350

      DƩneigement

      DƩglaƧage / Sel

      18

      -18

      5410

      Paysagement

      Entretien

      2,200

      5420

      Paysagement

      RƩparations / remplacement

      200

      5500

      ƉlectricitĆ©

      ƉlectricitĆ©

      1,300

      1,358

      -58

      5610

      Honoraires professionnels

      Juridiques

      379

      -379

      5700

      Interphone

      Interphone

      600

      626

      -26

      5710

      Frais bancaires

      Frais bancaires

      360

      319

      41

      5720

      Frais de rĆ©unions et d’assemblĆ©es

      Location de salle

      300

      264

      36

      5730

      DƩpenses diverses

      DƩpenses diverses

      500

      1

      499

      5910

      Contingence

      Contingence

      1,500

      5925

      Transfert entre fonds

      Transfert entre fonds

      -14,041

      20,682

      -34,723

      Ā 

      Ā 

      Ā 

      9,974

      46,196

      -36,223

      Ā 

      Ā Any idea on how to fix this?Ā Ā Ā  I tried splitting the query to have one table for the Budget and an other for the Actuals and linking both to a “calendar” table, but ended up having the same number repeating across lines…

      Ā Any help would be greatly appreciated!

      Ā Thanks!

    • Aubrey McKillop

      Member

      January 12, 2020 at 5:21 PM

      Stephane,Ā 

      You could wrap your formula with an IF State checking to make sure that budget and Actuals both have values.Ā  If they do use the calculate if they do not apply another value such as 0

      Aubrey

      ——————————
      Aubrey McKillop
      Director of IT
      Moncton NB
      ——————————
      ——————————————-

    • Stephane Gelinas

      Member

      January 12, 2020 at 5:51 PM

      Hello Aubrey,Ā 

      Thanks for your reply.Ā  Unfortunately it seems to yield the same results…Ā Ā 

      This is what I have tried :Ā 

      Ecart:=if(isblank(CALCULATE(SUMX(DataTable,DataTable[Montant]),DataTable[ScĆ©nario]=”Budget”)),0,CALCULATE(SUMX(DataTable,DataTable[Montant]),DataTable[ScĆ©nario]=”Budget”))-if(isblank(CALCULATE(SUMX(DataTable,DataTable[Montant]),DataTable[ScĆ©nario]=”RĆ©el”)),0,CALCULATE(SUMX(DataTable,DataTable[Montant]),DataTable[ScĆ©nario]=”RĆ©el”))

      Best regards,Ā 

      Stephane

      ——————————————-

    • Paul Cooper

      Member

      January 13, 2020 at 1:58 AM

      The key is in the problem with many to many relationships.
      The budget table cannot have a relationship with the actuals table as the account key will have many in both tables. That is no one-to-many relationship.
      I solved this by creating a table with just the account numbers.Ā  You may have that already, if so, that step is done.
      Then use TREATAS to get the Budget Table to TREAT this account number (in the budget table) AS the Account Number in the Accounts table.
      Alternatively use the TREATAS with SUMMARIZE to achieve this.
      Excel will not recognise the TREATAS in intellisense as you type the formula but it actually does work.

      For detail see Matt Allington’s post here.
      Virtual Filters Using TREATAS

      Exceleratorbi remove preview
      Virtual Filters Using TREATAS
      I have been aware of the TREATAS function for a very long time. I have tried to understand how it works a few times but could never really work it out. I think part of the problem is the function name TREATAS is not very descriptive.
      View this on Exceleratorbi >

      ——————————
      Paul Cooper
      Director
      Rinstrum Pty Ltd
      Acacia RIdge
      0418744345
      ——————————
      ——————————————-

    • Stephane Gelinas

      Member

      January 13, 2020 at 8:10 PM

      Hello,

      Thank you for the reply,Ā  this seems promising, I will explore the option.

      Perhaps another way of solving this would be to add a bridge table, I just looked it up, it seems to be another way to fix the problems that can occur with many to many relationships.Ā  Perhaps I could split my information in two tables (one for budget, the other one for actuals), and use the accounts table as a bridge table… I’ll look into this as well.

      UPDATE

      I split the information in two tables and used the account table as a bridge between the actuals and the budget table.Ā  It seems to work correctly!

      My DAX formula now looks something like thisĀ  (translated as the formula uses some french terms) :

      =SUMX(‘Budget’,Budget[Budget])-SUMX(‘Actuals’,’Actuals'[Actuals])

      ——————————————-

    DSC Communities replied 5 years, 7 months ago 1 Member · 0 Replies
  • 0 Replies

Sorry, there were no replies found.

The discussion ‘DAX – Actual vs Budget variance, how to calculate when applying filter on same column’ is closed to new replies.

Start of Discussion
0 of 0 replies June 2018
Now

Welcome to our new site!

Here you will find a wealth of information created for peopleĀ  that are on a mission to redefine business models with cloud techinologies, AI, automation, low code / no code applications, data, security & more to compete in the Acceleration Economy!