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
Anonymous
Not applicable

How to sum a measure in a table?

Hello everyone

I'm sorry if this has been asked before, but I'm really fighting here. My boss has commissioned me to replicate an Excel report with Power BI, and I'm almost there, but for this one problem.

I'm trying to calculate a very custom sales increase, which in Excel is relatively simple as you point the formula to the cells you need. However, Power BI has required numerous DAX measures to get to this point, but that's fine. So, so far I have:

  1. YoY SHARE % CHANGE 2019 vs 2018 CALL FILE (taking the % of the one-year quota and subtracting from another year for all stores that are in the call file)
  2. YoY SHARE % CHANGE 2019 vs 2018 DO NOT CALL FILE(take the one-year odds percentage and subtract from another year for all stores that are not in the call file)
  3. YoY SHARE % CHANGE 2020 vs 2018 CALL FILE (as above)
  4. YoY SHARE % CHANGE 2020 vs 2018 DO NOT CALL FILE (as above)
  5. SHARE % DIFF 2019 vs 2018 CALL FILE VS NOT CALL FILE (measure 1 - measure 2)
  6. SHARE % DIFF 2020 vs 2018 CALL FILE VS NOT CALL FILE (measure 3 - measure 4)
  7. INCR SALES 2019 (2018 filtered sales dame sum * measure 5)
  8. INCR SALES 2020 (2018 filtered sales dame sum * measure 6)

As you can see, there are several measures needed to get to this point, and if I plan as a table looks good and the values match my Excel report. However, the Total rows do not add up:

MyINCR 2019 VENTASRETAILER 1 INCR SALES 2019RETAILER 2 INCR SALES 2019RETAILER 3 INCR SALES 2019RETAILER 4 INCR SALES 2019INCR SALES 2020RETAILER 1 INCR SALES 2020RETAILER 2 INCR SALES 2020RETAILER 3 INCR SALES 2020RETAILER 4 INCR SALES 2020
January44.304 euros1.611 euros-11.184 euros26.107 euros27,771 euros238.087 euros41.341 euros15.644 euros18,788 euros£162,314
February136,427 euros-1.418 euros-6.561 euros32.742 euros111.664 euros272,442 euros22.908 euros8.453 euros48.007 euros193.073 euros
March147,459 euros7.027 euros-3,599 euros78.056 euros65.976 euros129,178 euros54.368 euros2.871 euros£30,42341.515 euros
April211.106 euros1.719 euros-15.873 euros97.766 euros127,495 euros
Can248,852 euros£18,191£24,98060.964 euros144.716 euros
June365.241 euros25.249 euros16.516 euros128,764 euros£194,713
July271.421 euros-27.066 euros79.009 euros27,485 euros191.993 euros
August224,874 euros-1.282 euros58.197 euros65,183 euros102.777 euros
September113,407 euros-38.918 euros75.814 euros39.257 euros37.254 euros
October78,997 euros-7.884 euros47.042 euros6.998 euros32.842 euros
November£179,791-199 euros40.436 euros13.981 euros125,573 euros
December155.035 euros£24,70015.484 euros-19.527 euros134,377 euros
Total2.208.968 euros6.501 euros298.042 euros566,703 euros1.337,723 euros2.766,599 euros£551,740214,851 euros242.857 euros1.757,151 euros
HOW TOTAL SHOULD IT BE2.176,914 euros£1,730320.261 euros557,776 euros1.297,151 euros639,707 euros118,617 euros26,968 euros97.218 euros

396,902 euros

I understand that the DAX formula is applying the same calculations to the TOTAL row, but I just need to sum what's above! I've seen similar threads where people have had the same problem, but their data is always based on hard-coded data rather than fields.

Any ideas? I'm sorry about the long post...

Reagrds,


Rick

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Try using this measure pattern instead.  Keep your existing measures as you'll reference them in the new ones.

 

NewMeasure = sumx(values(Date[Month]), [ExistingMeasure]) // or use Date[YearMonth]

 

This measure pattern should give you the right result in both the rows and the total.

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

This looks like a measure totals problem. Very common. See my post about it here: 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


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
AllisonKennedy
Super User
Super User

Hi Rick

Sorry if I missed it but can you share the formulas for the measures you have already calculated, as you say this is a common problem with totals seeming 'wrong' in measure calculation, so if you can share your DAX formulas for the measures we can help you understand why they are 'wrong' and how you can fix them. 

 

Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 

 

If you found this post helpful, please give Kudos.

I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 

https://sites.google.com/site/allisonkennedycv


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

Hi Allison,

 

Thanks for getting back to me! The formulas I've provided are as follows:

 

1. 

DRINK NOW - RETAILER1 YoY SHARE % CHANGE 2019 vs 2018 CALL FILE =
CALCULATE( sum( Data[DRINK NOW - CLIENT]) / sum(Data[DRINK NOW - CATEGORY]),
Data[Callfile] = "Callfile" ,
Data[Year] = 2019 ,
Data[RETAILER] = "RETAILER1")
-
CALCULATE( sum( Data[DRINK NOW - CLIENT]) / sum(Data[DRINK NOW - CATEGORY]), Data[Callfile] = "Callfile" , Data[Year] = 2018 , Data[RETAILER] = "RETAILER1")

 

2.

DRINK NOW - RETAILER1 YoY SHARE % CHANGE 2019 vs 2018 NOT CALL FILE =
CALCULATE( sum( Data[DRINK NOW - CLIENT]) / sum(Data[DRINK NOW - CATEGORY]), Data[Callfile] = "Not Callfile" , Data[Year] = 2019 , Data[RETAILER] = "RETAILER1")
-
CALCULATE( sum( Data[DRINK NOW - CLIENT]) / sum(Data[DRINK NOW - CATEGORY]), Data[Callfile] = "Not Callfile" , Data[Year] = 2018 , Data[RETAILER] = "RETAILER1")

 

3. 

DRINK NOW - RETAILER1 YoY SHARE % CHANGE 2020 vs 2018 CALL FILE =
if (
ISBLANK(
CALCULATE(
sum(Data[DRINK NOW - CLIENT]) / sum(Data[DRINK NOW - CATEGORY]),
Data[Callfile] = "Callfile" ,
Data[Year] = 2020 ,
Data[RETAILER] = "RETAILER1") ) ,
BLANK() ,
CALCULATE( sum( Data[DRINK NOW - CLIENT]) / sum(Data[DRINK NOW - CATEGORY]), Data[Callfile] = "Callfile" , Data[Year] = 2020 , Data[RETAILER] = "RETAILER1")
-
CALCULATE( sum( Data[DRINK NOW - CLIENT]) / sum(Data[DRINK NOW - CATEGORY]), Data[Callfile] = "Callfile" , Data[Year] = 2018 , Data[RETAILER] = "RETAILER1") )

 

4.

DRINK NOW - RETAILER1 YoY SHARE % CHANGE 2020 vs 2018 NOT CALL FILE =
if (
ISBLANK(
CALCULATE(
sum(Data[DRINK NOW - CLIENT]) / sum(Data[DRINK NOW - CATEGORY]),
Data[Callfile] = "Not Callfile" ,
Data[Year] = 2020 ,
Data[RETAILER] = "RETAILER1") ) ,
BLANK() ,
CALCULATE( sum( Data[DRINK NOW - CLIENT]) / sum(Data[DRINK NOW - CATEGORY]), Data[Callfile] = "Not Callfile" , Data[Year] = 2020 , Data[RETAILER] = "RETAILER1")
-
CALCULATE( sum( Data[DRINK NOW - CLIENT]) / sum(Data[DRINK NOW - CATEGORY]), Data[Callfile] = "Not Callfile" , Data[Year] = 2018 , Data[RETAILER] = "RETAILER1") )

 

5.

DRINK NOW - RETAILER1 SHARE % DIFF 2019 vs 2018 CALL FILE VS NOT CALL FILE =

[DRINK NOW - RETAILER1 YoY SHARE % CHANGE 2019 vs 2018 CALL FILE] - [DRINK NOW - RETAILER1 YoY SHARE % CHANGE 2019 vs 2018 NOT CALL FILE]

 

6.

DRINK NOW - RETAILER1 SHARE % DIFF 2020 vs 2018 CALL FILE VS NOT CALL FILE =

[DRINK NOW - RETAILER1 YoY SHARE % CHANGE 2020 vs 2018 CALL FILE] - [DRINK NOW - RETAILER1 YoY SHARE % CHANGE 2020 vs 2018 NOT CALL FILE]

 

7.

DRINK NOW - RETAILER1 INCR SALES 2019 =

CALCULATE(
sum(Data[DRINK NOW - CATEGORY]),
Data[Callfile] = "Callfile" ,
Data[Year] = 2018 ,
Data[RETAILER] = "RETAILER1" )
* [DRINK NOW - RETAILER1 SHARE % DIFF 2019 vs 2018 CALL FILE VS NOT CALL FILE]

 

8.

DRINK NOW - RETAILER1 INCR SALES 2020 =

CALCULATE(
sum(Data[DRINK NOW - CATEGORY]),
Data[Callfile] = "Callfile" ,
Data[Year] = 2018 ,
Data[RETAILER] = "RETAILER1" )
* [DRINK NOW - RETAILER1 SHARE % DIFF 2020 vs 2018 CALL FILE VS NOT CALL FILE]

 

In short, formulas 1 & 2 are used to make formula 5, which is then in turn applied with data from the original source to create formula 7.

 

Sorry for the long formulas, I am self-taught for the most part!

mahoneypat
Employee
Employee

Try using this measure pattern instead.  Keep your existing measures as you'll reference them in the new ones.

 

NewMeasure = sumx(values(Date[Month]), [ExistingMeasure]) // or use Date[YearMonth]

 

This measure pattern should give you the right result in both the rows and the total.

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Thanks Pat - this worked a charm!

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.