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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
mumair
Helper I
Helper I

Filtering Data

Here is my example data

 

Order # | Train # | Product | Location | Tonnage | Load Time

Order 1 | Train A | Product 1 | New York | 72 | 45

Order 2 | Train A | Product 1 | New York | 64 | 53

Order 3 | Train A | Product 1 | New York | 76 | 36

Order 4 | Train B | Product 1 | New York | 45 | 65

Order 5 | Train C | Product 1 | LA | 55 | 67

Order 6 | Train C | Product 2 | LA | 43 | 43

Order 7 | Train D | Product 1 | LA | 35 | 10 

 

I want to calculate RATE i.e. Tonnage / Load Time. However, I need to calculate it in a specfic way. If the same product is being loaded on the same train, it is assumed to be loaded simulataneously. This can be seen in Orders 1 - 3. Therefore the correct rate is (72 + 64 + 76)/ 53 = 4.0. I also need to know the load rate of product in every location. This would be (4.0 + 45/65 + 55/67 + 35/10)/4 = ~2.25 for Product 1. Furthermore, I need to know the load rate of every location. For LA, this would be calculated as (55/67 + 43/43 + 35/10)/3 = ~1.77. Lastly, I need to konw the rate of a particular product in a particular location. For Product 1 in LA, this would be (55/67 + 35/10) = ~2.16.

 

How would I write DAX to accomplish these goals?

 

 

 

3 REPLIES 3
v-qiuyu-msft
Community Support
Community Support

Hi @mumair,

 

You can create measures below. Please see attached .pbix file.

 

rate = CALCULATE(SUM(Table1[Tonnage]),FILTER(ALLSELECTED(Table1),'Table1'[Train #]="Train A" && 'Table1'[Product]="Product 1"))/
CALCULATE(MAX('Table1'[Load Time]),FILTER(ALL(Table1),'Table1'[Train #]="Train A" && 'Table1'[Product]="Product 1"))

 

Pro1 = var T=CALCULATE(SUM(Table1[Tonnage]),FILTER(ALLSELECTED(Table1),'Table1'[Train #]=MAX('Table1'[Train #]) && 'Table1'[Product]=MAX('Table1'[Product])))
return
(SUMX(FILTER(ALL(Table1),'Table1'[Product]="Product 1"&& 'Table1'[Train #]<>"Train A"),DIVIDE('Table1'[Tonnage],'Table1'[Load Time]))+'Table1'[rate])/'Table1'[rate]

 

ForLA = SUMX(FILTER(ALL('Table1'),'Table1'[Location]="LA"),DIVIDE('Table1'[Tonnage],'Table1'[Load Time]))/COUNTAX(FILTER(ALL(Table1),'Table1'[Location]="LA"),'Table1'[Location])

 

P1-LA = SUMX(FILTER('Table1','Table1'[Location]="LA" && 'Table1'[Product]="Product 1"), DIVIDE('Table1'[Tonnage],'Table1'[Load Time]))

 

Best Regards,
Qiuyun Yu

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

Is there a way to make it more general? I don't need it just for those specific calculations, but for all of them across a much larger table.

mumair
Helper I
Helper I

For clarification, we care about the total time it takes the total product to get on the train in calculating the rate.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.