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
CoreX
Regular Visitor

Create a SUM measure that sums conditionally

Hi all,

 

I'm new to Power BI and am really happy with some of the progress I'm making in visualizing my data, but I'm having some trouble getting the data to be presented in the way I need it.

 

I have a table of data where I'm trying to create a measure based on two of the columns.  Some example data below.

 

Order NumberRun Time
100015
1000160
1000110
1000180
100024
1000210
100025
1000390
1000450
1000475
1000460
1000410

 

I want the measure to sum the total run time for each order number giving me the following data for use elsewhere:

 

Order NumberRun Time
10001155
1000219
1000390
10004195

 

Thank you very much for any help you can give!

1 ACCEPTED SOLUTION

@CoreX,

 

For this requiremnt, you can create two calculated table to achieve it.
Table2 = SUMMARIZE(Table1,Table1[Part Number],Table1[Order Number],"TotalRunTime",CALCULATE(SUM(Table1[Run Time]),ALLEXCEPT(Table1,Table1[Part Number],Table1[Order Number])),"Output Quantity",CALCULATE(MAX(Table1[Output Quantity]),ALLEXCEPT(Table1,Table1[Part Number],Table1[Order Number])))

Capture.PNG 

 

Table3 = SUMMARIZE(Table2,Table2[Part Number],"TotalRunTime",CALCULATE(SUM(Table2[TotalRunTime]),ALLEXCEPT(Table2,Table2[Part Number])),"TotalOutputQuantity",CALCULATE(SUM(Table2[Output Quantity]),ALLEXCEPT(Table2,Table2[Part Number])))
Average = Table3[TotalRunTime]/Table3[TotalOutputQuantity]
Capture1.PNG

 

Regards,

Chalrie Liao

View solution in original post

4 REPLIES 4
Sean
Community Champion
Community Champion

Run Time Total = SUM ( TableName[Run Time] )

Should be all you need if you create a table Visual and drag Order Number and Run Time Total to the fields

In fact you don't even need to create a Measure for this (drag Run Time and it should default to Sum)

Because you'll have Order Number in the Table it will calculate the run time per Order Number no need to add a filter in a Measure!

If you insist

Run Time per Order Number = CALCULATE ( SUM ( TableName[Run Time] ), ALLEXCEPT ( TableName, TableName[Order Number] ) )

But that's really not necessary...

Vvelarde
Community Champion
Community Champion

@CoreX

 

Hi, Put in a table visual Order Number and RunTime

After That Click in Run Time and Select Sum.

 

Sum.png




Lima - Peru

Thanks Vvelarde, that certianly gets what I'm needing but not what I want.  This is my mistake for not fully explaining my goal.

 

I need to know what the total Run Time is for every Order Number so that I can then average that run time against a Quantity column which is also in the data to give me an average Run Time per Part Number.  Below is a more representative set of data to help explain what I'm trying to do.  (Note:  for Output Quantity I will pull the MAX value as these are not summed.  Example:  10001 has a total output quantity of 15, not 60).

 

Order NumberPart NumberRun TimeOutput Quantity
10001Widget A515
10001Widget A6015
10001Widget A1015
10001Widget A8015
10002Widget B410
10002Widget B1010
10002Widget B510
10003Widget A905
10004Widget B5020
10004Widget B7520
10004Widget B6020
10004Widget B1020

 

This data will be summarized and presented as part of several visualizations.

 

Part NumberAverage Run Time
Widget A12.25
Widget B7.13

@CoreX,

 

For this requiremnt, you can create two calculated table to achieve it.
Table2 = SUMMARIZE(Table1,Table1[Part Number],Table1[Order Number],"TotalRunTime",CALCULATE(SUM(Table1[Run Time]),ALLEXCEPT(Table1,Table1[Part Number],Table1[Order Number])),"Output Quantity",CALCULATE(MAX(Table1[Output Quantity]),ALLEXCEPT(Table1,Table1[Part Number],Table1[Order Number])))

Capture.PNG 

 

Table3 = SUMMARIZE(Table2,Table2[Part Number],"TotalRunTime",CALCULATE(SUM(Table2[TotalRunTime]),ALLEXCEPT(Table2,Table2[Part Number])),"TotalOutputQuantity",CALCULATE(SUM(Table2[Output Quantity]),ALLEXCEPT(Table2,Table2[Part Number])))
Average = Table3[TotalRunTime]/Table3[TotalOutputQuantity]
Capture1.PNG

 

Regards,

Chalrie Liao

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.