weighted average
12 TopicsSUMX with Calculated() - Weighted average can't be calculated
Hello all, so for some context, i'm trying to calculate a forecast accuracy with weighted average, meaning when it's all summed up, i want a value that is influenced by how much weight each row has. For the calculation i need to access different key figures, which are defined in a single row called "key figure". For the calculation of the Forecast accuracy i can just use some calculate formulas and it works perfectly fine. Problem is, when i try to make the normal forecast accuracy weighted. I tried to do this with SUMX, but it somehow gives me values that are not possible. I put much time in research and couldn't find anything. I assume that with the SUMX, some filter context of the defined variables get lost (not sure though). Anyway, here's the original DAX formula for the forecast accuracy (not weighted yet). it works as intended: result of this formula. on single row basis this works, but the total (yellow) is not weighted, which is what i try to achieve: So here is the new dax formula, that i created to get the forecast accuracy to be weighted: The result is not possible. On single row bases, the value need to be identical to the above ones, but they aren't. The total doesn't make any sense at all: I was pretty confident that the formula makes sense, but i'm probably missing something. Is this entire thing not possible, because the key figures are in one single colums, just like the values (volume cs) are in the same column? Thanks! 😃 Best regards NicolasSolved1.9KViews0likes3CommentsWeighted Average by Customer and Product
Hi all, Sorry if this has been answered elsewhere, but looking for some hopefully easy help. I am new to Power BI having extensive knowledge in QlikSense. I know the logic around how this should be done (AGGR in QS) but am not finding the right/best way in DAX to handle. Basically I would like to have the weighted average cost by customer and by product. A sample table and expected results are below. I'd like to pull this value in a whisker table with just one dot per customer and product - doing a straight average of Cost is misleading. One small caveat - in the source data, there are different amount of rows per "cost per unit" per Customer as this is actually distribution customers, meaning Customer A might have 10 end-customers who buy through them at $1.00, 5 customers who buy through them at $0.80, etc. So we have to be careful about summing up Unit Cost and likely should use average/distinct instead. I'm sure this is a mix of sumx, calculate, evaluate, etc but proving fruitless so far. Below is a table that I hope comes through ok. Thank you for your help! Product Customer Cost per Unit Units PurchasedTotal Cost Weighted Average Cost A Adams $ 1.00 50 $ 50.00 A Adams $ 0.80 100 $ 80.00 A Adams $ 1.24 10 $ 12.40 $ 0.90 A Smith $ 1.25 50 $ 62.50 $ 1.25 A Russel $ 0.90 25 $ 22.50 $ 0.90 B Adams $ 25.00 21 $ 525.00 B Adams $ 30.00 10 $ 300.00 $ 26.61 B Smith $ 25.00 100 $ 2,500.00 B Smith $ 15.00 75 $ 1,125.00 $ 20.71Solved816Views0likes1CommentWeighted Time Average from table of times.
I've got a calendar table of dates, and have created a SUMMARIZECOLUMNS measure that tabulates every 'event time' within that day, and the active quantity at that time. For example, for the 29th of January this table is generated: Event Time Active Quantity 29/01/2024 08:00 100 29/01/2024 09:00 125 29/01/2024 12:00 300 29/01/2024 15:00 300 29/01/2024 17:00 200 29/01/2024 22:00 25 I'm trying to calculate the Average Active Quantity, weighted by the amount of time between Events. To calculate this I need to generate an intermediate table, with each time period: Start Time End Time Hours Difference Active Quantity 29/01/2024 08:00 29/01/2024 09:00 1 100 29/01/2024 09:00 29/01/2024 12:00 3 125 29/01/2024 12:00 29/01/2024 15:00 3 300 29/01/2024 15:00 29/01/2024 17:00 2 300 29/01/2024 17:00 29/01/2024 22:00 5 200 How would I generate this table, and finally calculate the Average of 'Active Quantity' weighted by 'Hours Difference' in one measure?Solved1KViews0likes2CommentsREALLY hoping for some help on Dynamic Weighted Averages please
Hi there! I'm very new to Power BI and am really hoping for some help. I'm attaching two versions of the PBIX and an Excel showing the general workings that I'm aiming for. Excel workings PBIX where overall weighted average is correct but it can't rebalance where user applies filters PBIX where the weight column correctly rebalances when user applies filters, but then weighted avera... NOTE: only difference between these two files is the FlexibleGroupWeight measure Essentially I have a portfolio with a list of stock weights. There are multiple rows per stock, duplicating the stock weight data. Each unique row is for various metrics on the stocks (ROE, beta etc). For each stock, I need to calculate a weighted average for a metric. When the metric isn't available for a stock, it should automatically rebalance (to 100% in total) the weights for the stocks where the data is available. Crucially, I'm hoping the weighted average can be dynamic. i.e. when users filter clicking within the dashboard, the weighted average recalculates. So if we filtered to four 5% stocks that total 20% of portfolio, because it's filtered this would all rebalance to 100% and the 5% stocks all become 25% for example. Hopefully you can see what I'm getting at - I've included an Excel workbook to show how I would use SUMIFs to achieve the first of these effects (filtering out and rebalancing stocks based on data availablility). So the Excel shows arrives at the correct aggregate weighted averages for each metric based on the sum of [RebalancedWeight]*[Value] rows for a metric. You can see these correct weighted averages in Column I. In the Power BI reports, it hinges on the "FlexibleGroupWeight" measure. In the first file, everything calculates correctly at the aggregate level, and therefore produces correct weighted average metrics ("WA-Metric" column). HOWEVER - it cannot handle user-applied filters (the measure is only using ALLEXCEPT). In the second PBIX, the "FlexibleGroupWeight" measure can handle the user-filtering process.. You click the pie chart to filter on a particular sector, and the number in the first column correctly drops to just the % of the portfolio we are filtered to. The rebalancing should then work off this smaller total to do a weighted average in that sector only. However - suddenly the actual weighted average metrics are WAY out and it looks as though they become the sum of all the individual stock metric values.. In latter case my measure uses ALLSELECTED whereas first case uses ALLEXCEPT... Is there some way of combining these two formulas please to get the desired effect? I think that it what would finally get me there! THANK YOU SO SO MUCH IN ADVANCE FOR ANY HELP!!1.4KViews0likes1Commentmeasure to distribute specific row share among the other row values as per share percentage
I have a data something like below table, and the need is to distribute the blank tag cost among the other tag according to their related share of not blank value. Example.. tag cost aaa 100 bbb 10 ccc 40 ddd 50 (blank) 80 bbb 60 ccc 30 ddd 20 aaa 40 (blank) 500 (blank) 100 Expected calculation for aaa the share will be "140/(100+20+30+50+60+30+20+40)" = 40% of 680 for bbb the share will be "70/(100+20+30+50+60+30+20+40)" = 20% of 680 for ccc the share will be "70/(100+20+30+50+60+30+20+40)" = 20% of 680 for ddd the share will be "70/(100+20+30+50+60+30+20+40)" = 20% of 680 expected solution tag cost %share total Share aaa 140 40% of 680 272 bbb 70 20% of 680 136 ccc 70 20% of 680 136 ddd 70 20% of 680 136Solved1.6KViews0likes4CommentsCreating a "weighted" bell curve measure
I have a table that roughly looks like this Program ID Sales Program Name Program Start Date Program End Date Units to Push 0001 ABC Aug-8th-2023 Aug-28th-2023 34 0002 DEF Aug-15th-2023 Sept-29-2023 57 003 GHI Sept-01-2023 Sept-29-2023 45 The users would like me to apply a bell curve to help them determine theoritically how many units to push per day depending on how far into the program they are (with an emphasis on the middle). So roughly the first 25% of the program they would be expecting to push more, same for the last 25% of the program, with the middle 50% expecting a bit of a lull. I've done so by creating several calculated columns: First one is a datediff between start and end date in days Second one is a division of Today minus start date over the total length of the program to get the progress of the program so far Third is the average units per day (total Units divided by number of days). With that I was able to create a calculated column with an IF Statement that basically checks what the Progress is and adds a modifier to the Average (minus or plus depending on where in the program). Weighted Sales = IF ( SalesProgram[ProgramProgress] <> 0 && SalesProgram[Program Length] > 10, IF ( SalesProgram[ProgramProgress] <= 0.25 || SalesProgram[ProgramProgress] >= 0.75, SalesProgram[AverageDailySales] * 1.5, SalesProgram[Average DailySales] *0.5 ), IF ( SalesProgram[ProgramProgress] <> 0 && SalesProgram[Program Length] <= 10, SalesProgram[AverageDailySales] ) ) note that they consider sales program under 10 days to just have average every day, no bell hence the extra logic for that My problem is that I've done all of this in calculated columns using TODAY as a checking point since they want to see their expectations for the day at the beginning, therefore I have no way to build a cumulative running total. How would I best go about transforming that calculation column into a measure that can track over tie (the table is connected to a calendar dimension)?Solved1.2KViews1like4CommentsMeasure to calculate weighted average of days a stock was held before being sold
Below is a snippet of a facts table 'fTrans' containing historical purchase and sale transactions of shares of stock. [Ticker], [Date], [Sale date related to respective purchase], [Transaction], [Shares] and [Price] are the imported data. [Days] is a measure where [Sale date related to respective purchase] - [Date], hence the time each batch of shares was held before being sold. And [Purchase total] is another measure that computes [Shares] x [Price]. What I need is to calculate the AVERAGE of days each batch of shares was held until its respective SALE transaction took place. As you can see by the expanded snippet below, this is quite a straightforward exercise when a particular sale transaction relates one-on-one to a prior purchase transaction. However things get a bit more complicated as there are instances where a particular sale refers to TWO OR MORE prior purchase transactions, which I highlight some examples below. And to complicate matters further I DO NOT want to calculate a simple straight average by just summing up the days and dividing them up by the number of occurrences. That average calculation needs to be a weighted average using [Purchase total] as the weight basis for each transaction. So I started constructing a couple of temporary tables and then use the second one as the source table to grab the calculated average days for each respective sale date from by writing a third and final RETURN block of the measure code. On the intermediary table 'Supp_Tbl' I calculate the product between [Days] and [Purchase total], which will be used as the weight for each purchase transaction. Then I use 'Supp_Tbl' to calculate the [Weighted average days] and setup the second table 'Days_Tbl' by grouping the [Product of Days and Purchase total] and the [Purchase total] by [Ticker] and [Sale date related to respective purchase] so I can divide them up and then get the result for each sale date. And that's where I get stuck. I do have the results right in front of me and know what needs to be done on the RETURN block in order to get to the measure: Call 'fTrans' table and get each [Ticker]/[Date] combination. Call 'Days_Tbl' and scan it to find each row whose [Ticker]/[Sale date related to respective purchase] combination matches the one from step 1. Grab the respective [WghtdAvgDays] from the corresponding row found on step 2. I just seem not to know how! I've tried several paths such as setting up a third temporary table, INDEX or LOOKUPVALUE but to no avail. Maybe my mind is still too stuck in Excel and prevent me from thinking the DAX way. Any help is immensely appreciated...825Views0likes2CommentsDAX weighted average help for Power pivot
Rm Group Values Beans nuts Flour Date (Month) Document Sum of Outstanding Qty Weight2 Sum of Outstanding Qty Weight2 Sum of Outstanding Qty Weight2 Apr SG 1000000 1.068.350 1000000 3000000 700000 1700000 PN 68350 1.068.350 1000000 3000000 700000 1700000 Dxb 1000000 3000000 300000 1700000 Apr Total 1068350 3000000 1700000 May SG 1000000 2.000.000 PN 1000000 2.000.000 Dxb May Total 2000000 Jun SG PN Jun Total Jul SG PN Jul Total Oct SG PN Oct Total Nov SG PN Nov Total Dec SG PN Dec Total Grand Total I need help in creating a Dax formula for this pivot. I want the total outstanding qty for every month and group( Beans, nuts etc. to appear in the document rows ( just the yellow numbers.) How can I compute a DAX formula for that? Would really love to hear some suggestions as I have been struggling with this for days!Solved955Views0likes2CommentsWeighted Average by Distinct Category
Hello PBI Community, I'm fairly new to DAX and am trying to write a DAX formula to calculated weighted average by distinct category as follows: The table structure is this: Row ID (Key)__ Category___ Place Name__ Total Sample__ Average Size within Sample 123 A Indiana 1400 14 232 A Ohio 1400 14 111 B New Jersey 300 30 Values for Total Sample and Average Size within Sample columns are grouped by category (i.e each rows with the same category will have the same value for those 2 columns). I am trying to calculate the folowing weighted average by distinct category. For the data above, the result I would want is below: [ (1400 x 14) + (300 x 30) ] / (1400+300) = 16.82 (This is the desired result). In a slicer if Place Name Indiana, Ohio and New Jersey are selected, I would want this value. The result will also be same if only Indiana and New Jersey are selected. If only Indiana and Ohio are selected (places with same category), I would not want to do any aggregation and only display the calucation as 14. I have created a DAX formula below that does not take into account the distinct category which gives the below: DIVIDE( SUMX('Table','Table'[Total Sample]*'Table'[Average Size within Sample]), SUM('Table'[Total Sample])) Translates to: [(1400 x 14) +(1400 x 14) + (300 x 30)] / [ (1400+1400+300)] = 15.54 (This is not the desired result) Any help that can be suggested to modify the formula to get the desired result will be appreciated. Thank you so much.Solved751Views0likes2CommentsWeighted AVG Calculation
Hey all, I have the following data table with many names but I only copied the table with 2 names now: setup.py and path.xyz. (date, name, loc_i, loc_d columns are originally in the table, and AGE, Weight, Weighted AVG are calculated. date name loc_i loc_d AGE Weight Weighted AVG 24/01/22 13:20:06 setup.py 41 0 129.44 33 4271.664375 27/01/22 11:31:23 setup.py 1 1 126.52 1 126.5198727 28/01/22 08:54:20 setup.py 1 1 125.63 1 125.6289352 09/03/22 08:22:06 setup.py 2 2 85.65 2 171.3026389 05/04/22 07:57:04 setup.py 1 0 58.67 1 58.6687037 05/04/22 07:54:23 setup.py 1 0 58.67 1 58.67056713 27/01/22 09:45:36 setup.py 2 2 126.59 2 253.1866667 28/01/22 08:46:19 setup.py 2 2 125.63 2 251.2690046 123.6491 24/01/22 13:20:06 path.xyz 35 0 129.44 26 3365.55375 27/01/22 11:31:23 path.xyz 2 1 126.52 2 253.0397454 28/01/22 08:54:20 path.xyz 1 0 125.63 1 125.6289352 09/03/22 08:22:06 path.xyz 1 0 85.65 1 85.65131944 05/04/22 07:57:04 path.xyz 1 0 58.67 1 58.6687037 05/04/22 07:54:23 path.xyz 1 1 58.67 1 58.67056713 27/01/22 09:45:36 path.xyz 1 1 126.59 1 126.5933333 28/01/22 08:46:19 path.xyz 1 1 125.63 1 125.6345023 24/01/22 13:30:06 path.xyz 1 1 129.44 1 129.4374306 28/01/22 11:31:23 path.xyz 2 2 125.52 2 251.0397454 28/01/22 08:55:20 path.xyz 2 2 125.63 2 251.2564815 123.8763 Here you can see the formulas behind the calculated columns: I would like to create the final calculation in PBI somehow (please note that my data table consists of more than 2 names - thousands). Many thanks in advance!Solved895Views0likes3Comments