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
vassilev1914
Frequent Visitor

Wrong Totals & SUMIFS for sum in period between two dates

Dear Community,

I've been struggling for more than a week with the following problem:

I was asked to create a template for our Key Account managers in which they will be able to prepare promotional activities on their own and get actuals by updating a pivot table linked with Sales database. (I am using PowerPivot in Excel)

So, in a nutshell:

I've got a few tables: 

One Fact table (representing the Sales Actuals database):
Year     Month    Date        Product   Store     Volume

201911.1.2019SkatesStore A1000
201911.1.2019ScooterStore A2000
201911.1.2019BikeStore A3000
201911.1.2019SkatesStore B667
201911.1.2019ScooterStore B1333
201911.1.2019BikeStore B2000
201921.2.2019SkatesStore A1100
201921.2.2019ScooterStore A2200
201921.2.2019BikeStore A3300
201921.2.2019SkatesStore B733
201921.2.2019ScooterStore B1467
201921.2.2019BikeStore B2200

 

One Target table where the managers will prepare the activities by setting periods and targets for the stores (last two columns are calculated):

  

Start                           End                            Store      Product  Target Duration(days)    Period (concatenated)

15.2.2019 г. 0:00:0031.3.2019 г. 0:00:00Store ASkates12004415.2.2019 г.-31.3.2019 г.
15.2.2019 г. 0:00:0031.3.2019 г. 0:00:00Store ABike29004415.2.2019 г.-31.3.2019 г.
15.2.2019 г. 0:00:0031.3.2019 г. 0:00:00Store AScooter20004415.2.2019 г.-31.3.2019 г.
1.1.2019 г. 0:00:0031.3.2019 г. 0:00:00Store BSkates800891.1.2019 г.-31.3.2019 г.
1.1.2019 г. 0:00:0031.3.2019 г. 0:00:00Store BBike1800891.1.2019 г.-31.3.2019 г.
1.1.2019 г. 0:00:0031.3.2019 г. 0:00:00Store BScooter1100891.1.2019 г.-31.3.2019 г.
1.4.2019 г. 0:00:0031.8.2019 г. 0:00:00Store ABike140001521.4.2019 г.-31.8.2019 г.

I also have Date table, Customer table and Product table with the respective unique components.

 

What I managed to do is the following:

Pivot table where I have the Period of activity, Store, Target Vol, Actuals and Act vs Target

PeriodStoreProductTarget QtyActual ResultsAct vs Target (vol)Act vs Target %
1.1.2019 г.-31.3.2019 г.Store BBike1 8006 1004 300238,9%
  Scooter1 1004 0672 967269,7%
  Skates8002 0331 233154,2%
1.4.2019 г.-31.8.2019 г.Store ABike14 00015 9601 96014,0%
15.2.2019 г.-31.3.2019 г.Store ABike2 9002 850-50-1,7%
  Scooter2 0001 900-100-5,0%
  Skates1 200950-250-20,8%
Grand Total  23 80083 70059 900251,7%

 

Basically everything is as I wanted except the total for the Actuals which is wrong due to the DAX row context. Here you are the formula for the actuals that takes the figures from Fact table:

 CALCULATE(
               SUM(Fact[Volume]);
                          FILTER(Fact;(Fact[Date]>=MIN(Target[Start])));FILTER(Fact;(Fact[Date]<=MAX(Target[End]))))

 

How the hell am I supposed to fix these totals. Watched tens of videos and read a lot of articles. Nothing worked so far. I tried with workaround by adding calculated column in the Target table that would represent SUMIFS and just calculate the figures for each row but with no success in figuring out the right formula.

 

Please help...

 

1 ACCEPTED SOLUTION
v-lili6-msft
Community Support
Community Support

HI, @vassilev1914 

This is a measure totals problem. Very common. See this post about it
https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

If you still have the problem, please share your sample pbix file for us have a test.

Please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

You can upload it to OneDrive and post the link here. Do mask sensitive data before uploading.

 

Best Regards,

Lin

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

View solution in original post

4 REPLIES 4
v-lili6-msft
Community Support
Community Support

HI, @vassilev1914 

This is a measure totals problem. Very common. See this post about it
https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

If you still have the problem, please share your sample pbix file for us have a test.

Please see this post regarding How to Get Your Question Answered Quickly:
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

You can upload it to OneDrive and post the link here. Do mask sensitive data before uploading.

 

Best Regards,

Lin

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

Many thanks for the response. It was useful.

Anyway, I found a workaround by inserting calculated column in the Target Table for getting the figures I need and thus the right totals. Here is the formula:

=CALCULATE(
      SUM(Fact[Volume]);filter(Fact;Fact[Product]=Target[Product]);FILTER(Fact;Fact[Store]=Target[Store]);DATESBETWEEN(Fact[Date];[Start];[End]))

hi, @vassilev1914 

It's pleasant that your problem has been solved, please accept the reply as solution, that way, other community members will easily find the solution when they get same issue . Thanks.  Smiley Very Happy

 

Best Regards,

Lin

Community Support Team _ Lin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
vassilev1914
Frequent Visitor

Anyone? 😞

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.