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
GilesWalker
Skilled Sharer
Skilled Sharer

DAX formula not totaling correctly

Hi everyone,

 

I am having trouble with a DAX formula not summing properly. It is due to me not filtering correctly however after many days of trying different variations I cant seem to get it to work. Here is the data and formula:

Capture.JPG

 

 

This data is coming from two tables:

1. Concentrates

2. DateKey

 

The concentrates table contains the week and all the revenue columns. The DateKey contains the Financial month column. The two tables are joined with a One-Many both ways relationship on a column I made which contains the financial year (2016) and the weeks (1-53) combined, this column is in both tables.

 

What I am trying to acheive is to work out what the revenue/budget is for the month. The issue is we only measure by week, and some weeks will cross over months. An example is week five in the above picture. What I have done to combat this is create a measure which calculates the number of days in a week relative to the month:

 

Countrows YearWeek = CALCULATE(SUM(DateKey[Index 1]), DISTINCT(DateKey[Financial YearWeek]))

 

The DateKey[Index 1] is just a column containg a value of 1 for every row.

 

I then added this measure in the concentrates table as a column:

 

Days in week = [Countrows YearWeek]

 

Next I created the following measure to calculate the Daily budget:

 

Daily budget revenue = DIVIDE(SUM(Concentrates[Budget $ concentrates]),[Countrows YearWeek])

 

This was then added into the concentrates table as a column:

 

Daily budget revenue concentrates = [Daily budget revenue]

 

I then created this measure to give me the daily budgeted revenue * the days in the week dependant on the month:

 

Monthly budget concentrates = [Daily budget rev concentrates]*[Countrows YearWeek]

 

As you can see from the picture above each it works, however the total is showing too much, it should be roughly 4 million not 224 million. I beleive the reason is because I am missing something in the filtering. I have have tried adding in ALLEXCEPT for the month or the week and it still results in the same total figure.

 

Hope someone can assist.

 

Thanks,

 

Giles

 

 

1 ACCEPTED SOLUTION
Sean
Community Champion
Community Champion

Have you seen this post...

http://www.powerpivotpro.com/2012/03/subtotals-and-grand-totals-that-add-up-correctly/

 

I'm not quite clear how your orginal 'concentartes' table is set up?

View solution in original post

4 REPLIES 4
Sean
Community Champion
Community Champion

@GilesWalker Can you post sample data so we can try to create the same table visual as the picture you posted?

@Sean - here you go:

 

WeekCountrows YearWeekRevenue $ actualBudget $ concentratesDaily revenueDaily budget revenueDaily budget revenue concentratesFinancial monthMonthly budget concentrates
 5     Jun 
14638992786715974.756966.75$6,966.75Jul27867
27847414876612105.857146966.571429$6,966.57Jul48766
37840784876612011.142866966.571429$6,966.57Jul48766
47773914876611055.857146966.571429$6,966.57Jul48766
56993034876616550.58127.666667$6,966.57Jul41799.42857
5199303487669930348766$6,966.57Aug6966.571429
67673334876696196966.571429$6,966.57Aug48766
77861264876612303.714296966.571429$6,966.57Aug48766
87-2293848766-3276.8571436966.571429$6,966.57Aug48766
971354514876619350.142866966.571429$6,966.57Aug48766
1021055558592252777.542961$12,274.57Aug24549.14286
105105555859222111117184.4$12,274.57Sep61372.85714
Sean
Community Champion
Community Champion

Have you seen this post...

http://www.powerpivotpro.com/2012/03/subtotals-and-grand-totals-that-add-up-correctly/

 

I'm not quite clear how your orginal 'concentartes' table is set up?

@Sean - Thanks for your help with this. The link you sent through explained my issues perfectly and with a little tweaking I got it to work:

 

Monthly budget concentrates =

         IF(COUNTROWS(VALUES(Concentrates[Financial YearWeek]))=1,

                  [Daily budget rev concentrates]*[Countrows YearWeek],

                            SUMX(VALUES(Concentrates[Financial YearWeek]),

                                  [Daily budget rev concentrates]*[Countrows YearWeek]))

 

Thanks,

 

Giles

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.