Forum Discussion
Measuring weighted dwell time
Below is my current table setup. I'm trying to measure average weighted dwell across these tables. Each order on Shipment Detail counts as one SID, and then there are entries on Multiple SID when an order contains more than one SID. The formula should be taking the date difference between ship_date and rcvdate multiplied by the number of SIDs for each order's weighted dwell and then dividing that by total number of SIDs. I just can't figure out how to do this in Power BI.
| dwell | numsids | wgt | |
| 10 | 5 | 50 | |
| 2 | 4 | 8 | |
| 8 | 1 | 8 | |
| 1 | 1 | 1 | |
| 5 | 5 | 25 | |
| 4 | 4 | 16 | |
| = 30 | = 20 | =108 |
Not correctly counting the numSIDs gets you 30/6 = 5, correctly counting numSIDs but not weighing them gets you 30/20 = 1.5, and correctly weighing them and counting them gets you 108/ 20 = 5.4 which should be the correct average dwell.
I thought maybe creating a new column on Fact Shipment Detail to hold the ship_date - rcvdate value per row, and then another new column holding the count of SIDs however numSids = DISTINCTCOUNT('Fact Multiple SID'[MOSD_Index]) is returning in every row the total count of entries on Fact Multiple SID (400,000) rather than the number of entries per row, which is under 5.
You can achieve this through SUMX. Pseudo code:
= DIVIDE(SUMX(table, dwell * numsids),SUMX(table,numsids),0)
2 Replies
- lbendlin
Super User
You can achieve this through SUMX. Pseudo code:
= DIVIDE(SUMX(table, dwell * numsids),SUMX(table,numsids),0)
- BurmeindNew Member
Thanks for the answer. This is the final code I ended up with:
Dwell time as column in Fact Shipment Detail
Dwelltime = DATEDIFF('Fact Shipment Detail'[RcvDate],RELATED('Fact Manifest'[Ship_Date]),WEEK) * 5 + WEEKDAY(RELATED('Fact Manifest'[Ship_Date])) - WEEKDAY('Fact Shipment Detail'[RcvDate])Weighted Dwell as measure
Weighted Dwell = DIVIDE( SUMX('Fact Shipment Detail', 'Fact Shipment Detail'[Dwelltime] * (counta('Fact Shipment Detail'[SID#]) + counta('Fact Multiple SID'[M_SID]) ) ), SUMX('Fact Shipment Detail', counta('Fact Shipment Detail'[SID#]) + counta('Fact Multiple SID'[M_SID])), 0 )