Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Calculating a Subtotal within a Measure

Dear BI Users,

 

In the table below, I have previous period and current period data that I am trying to use to calculate a Price Variance Measure.

 

July 2019 Retail (Problem set)         
  Previous Period Current PeriodPrice Variance
  CostMaterialsCost per Material Previous CostMaterialsCost per Material Current# of Sales CurrentPrice Variance
Designer 1          
Store 1          
 Lamb Leather $   5,000.002 $                                 2,500.00  $   5,500.002 $                               2,750.00250 $        (62,500.00)
 Cow Leather $   1,500.001 $                                 1,500.00  $   5,250.003 $                               1,750.00300 $        (75,000.00)
 Canvas $   2,000.002 $                                 1,000.00  $   1,250.001 $                               1,250.00500 $      (125,000.00)
Subtotal  $   8,500.005 $                                 1,700.00  $ 12,000.006 $                               2,000.001050 $      (315,000.00)
Store 2          
 Lamb Leather $   2,200.001 $                                 2,200.00  $   2,450.001 $                               2,450.00300 $        (75,000.00)
 Cow Leather $   5,100.003 $                                 1,700.00  $   3,900.002 $                               1,950.00350 $        (87,500.00)
 Canvas $   2,400.002 $                                 1,200.00  $   2,900.002 $                               1,450.00550 $      (137,500.00)
Total  $   9,700.006 $                                 1,616.67  $   9,250.005 $                               1,850.001200 $      (280,000.00)
Grand Totals  $ 18,200.0011 $                                 1,654.55  $ 21,250.0011 $                               1,931.822250 $      (623,863.64)

 

The following three fields are measures while the rest are normal columns.


Cost per Materials Previous = [cost Current]*[Materials Current]
Cost per Materials Current = [cost]*[Materials]
Price Variance = ([Cost per Materials Previous] – [Cost per Materials Previous]) * [# of Sale]

 

The issue I am having can be seen in the table above, in which the subtotals are not providing the sum of the values in each store, but rather calculating the measure using the subtotals of the columns within the measure. So, the subtotal of “Cost Per Material” is actually dividing the subtotal of the Cost column by the subtotal of the Materials column. The same is the case for the Price Variance function as well. This is throwing off the value of the grand total for all stores. I've tried numerous functions including various iterations of SUMX and have found no solution to getting an accurate sum of these measures.

 

My desired solution is seen in the table below, in which the Subtotal row equals the sum of the above values for each store, and all subtotals combine to a sum grand total. 

 

July 2019 Retail (Desired Solution)        
  Previous Period Current PeriodPrice Variance
  CostMaterialsCost per Material Previous CostMaterialsCost per Material Current# of Sales CurrentPrice Variance
Designer 2          
Store1          
 Lamb Leather $   5,000.002 $                                 2,500.00  $   5,500.002 $                               2,750.00250 $        (62,500.00)
 Cow Leather $   1,500.001 $                                 1,500.00  $   5,250.003 $                               1,750.00300 $        (75,000.00)
 Canvas $   2,000.002 $                                 1,000.00  $   1,250.001 $                               1,250.00500 $      (125,000.00)
Subtotal  $   8,500.005 $                                 5,000.00  $ 12,000.006 $                               5,750.001050 $      (262,500.00)
Store 2          
 Lamb Leather $   2,200.001 $                                 2,200.00  $   2,450.001 $                               2,450.00300 $        (75,000.00)
 Cow Leather $   5,100.003 $                                 1,700.00  $   3,900.002 $                               1,950.00350 $        (87,500.00)
 Canvas $   2,400.002 $                                 1,200.00  $   2,900.002 $                               1,450.00550 $      (137,500.00)
Subtotal  $   9,700.006 $                                 5,100.00  $   9,250.005 $                               5,850.001200 $      (300,000.00)
Grand Totals  $ 18,200.0011 $                               10,100.00  $ 21,250.0011 $                             11,600.002250 $      (562,500.00)

 

Any help or guidance you can provide would be greatly appreciated!

 

1 REPLY 1
parry2k
Super User
Super User

@Anonymous Read this post to get your answer quickly.

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



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors