cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
OverwhelmedGuy
New Member

DAX Measure for Subtracting columns from different tables (related by the dates table)

Hi there,

Its my first post, pls tell me when you need further Information.

Problem: there are two tables related by the dates table. Actual Cost is based on specific dates (e.g.: 01.05.2022; with duplicates), Expected Cost is based on Year Quarter (e.g.: 2022 Q2; no duplicates). I want to know the difference between expected and actual cost based on Year Quarter. Both tables are related to the Dates table (see picture). 

 

OverwhelmedGuy_1-1664439384445.png

 

i fooled around with sumx and related, but didn't really have any major breakthroughs. any idea how to solve this?

 

Thanks for helping

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@OverwhelmedGuy Maybe:

 

Measure =
  VAR __YearQuarter = MAX('Dates'[Year Quartal])
  VAR __Expected = MAXX(FILTER('Expected Cost',[Year Quarter] = __YearQuarter),[Prediction Sales])
  VAR __Actuals = SUM('Actual Cost'[Total Value])
RETURN
  __Expected - __Actuals
  

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@OverwhelmedGuy Maybe:

 

Measure =
  VAR __YearQuarter = MAX('Dates'[Year Quartal])
  VAR __Expected = MAXX(FILTER('Expected Cost',[Year Quarter] = __YearQuarter),[Prediction Sales])
  VAR __Actuals = SUM('Actual Cost'[Total Value])
RETURN
  __Expected - __Actuals
  

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Awesome! Dose the Job i guess 🙂 

However i coud observe something interesting, when totaling the measure (which i will not need):

 

- Everything looks fine, when selecting Q1 and Q2

OverwhelmedGuy_0-1664448152363.png

- The total gets an negative value, when also selecting Q3. showing the Value of Q3 - (Q1 + Q2)

OverwhelmedGuy_1-1664448304033.png

- When adding Q4 the total is positve again, but way to low.


I see there is a long way for me to understand dax. however your anser fixed my problem!

Helpful resources

Announcements
collabdays lisbon

CollabDays Lisbon - 26 November 2022

Sessions include practical, hands-on experience that will help you take the next step in your career and know-how.

Difinity Conference

Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

European Share Point Conference

European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Microsoft 365 Conference â__ December 6-8, 2022

Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.