conditional sum
8 TopicsConditional and selective sum with filters
Hey guys! how you doing? Just got an insight in my dax code, i've been working on the logic of it for a while and i think im getting somewhere, but still need help. I need the code to return the "out" and "available" status correctly for each order, in a way that it will always start with the earliest order then to the oldest. the reult i got for this actual data is right, but it changes when i change the values, getting wrong results, here is an example of the right result i got.: I have used many calculations and contitions to achieving this result, but the logic is still not complete. look at the result i get when change the values: The correct results for this last one would be available, out, available, out, out, available, out, out. The measure i am using is the "FinalCorrectStatus" you can find it in the file: DistributeStok The code is: FinalCorrectStatus = VAR CurrentItem = SELECTEDVALUE('DB_ORDERS'[Produto]) VAR CurrentOrderNum = SELECTEDVALUE('DB_ORDERS'[Pedido]) VAR StockAvailable = CALCULATE( SUM('Table Estoq'[Estoque Real]), 'Table Estoq'[Produto] = CurrentItem ) //soma normal soma sem condição cumulativamente VAR SomaNormal = SUMX( FILTER( ALLSELECTED('DB_ORDERS'), 'DB_ORDERS'[Pedido] <= CurrentOrderNum && 'DB_ORDERS'[Produto] = CurrentItem ), 'DB_ORDERS'[Quant. Falta] ) //Filtro de apoio para a SomaMaiorEstoq VAR SomaMaiorApoio = FILTER( ALLSELECTED('DB_ORDERS'), 'DB_ORDERS'[Pedido] <= CurrentOrderNum && 'DB_ORDERS'[Produto] = CurrentItem ) //soma apenas quando o valor da "SomaNormal" for maior que o estoque VAR SomaMaiorEstoq = SUMX( ADDCOLUMNS( SomaMaiorApoio, "@Acumulado", SUMX( FILTER( SomaMaiorApoio, 'DB_ORDERS'[Pedido] <= EARLIER('DB_ORDERS'[Pedido]) ), 'DB_ORDERS'[Quant. Falta] ) ), VAR TotalAcumulado = [@Acumulado] RETURN IF(TotalAcumulado > StockAvailable, 'DB_ORDERS'[Quant. Falta], 0) ) //diferenca entre A soma cumulativa normal e a soma apenas dos maiores que o estoque VAR Diferenca = SomaNormal - SomaMaiorEstoq //valor resultante de "Diferenca" + a quantidade do item no pedido VAR Dif_mais_QTFALT = Diferenca + SELECTEDVALUE('DB_ORDERS'[Quant. Falta]) //verifica se o estoque já atingiu seu limite, vai somando o que estiver dentro da condição de caber no estoque VAR SomaFinal = SUMX( FILTER( ALLSELECTED('DB_ORDERS'), 'DB_ORDERS'[Pedido] <= CurrentOrderNum && 'DB_ORDERS'[Produto] = CurrentItem && ( SUMX( FILTER( ALLSELECTED('DB_ORDERS'), 'DB_ORDERS'[Pedido] <= CurrentOrderNum && 'DB_ORDERS'[Produto] = CurrentItem ), 'DB_ORDERS'[Quant. Falta] ) <= StockAvailable || (Diferenca + 'DB_ORDERS'[Quant. Falta]) <= StockAvailable ) ), 'DB_ORDERS'[Quant. Falta] ) RETURN IF( ISBLANK(StockAvailable), "out", IF( SomaFinal <= StockAvailable && (Dif_mais_QTFALT <= StockAvailable), "available", "out" ) ) its very complex, and i am almost giving up.. Can anyone help me please? Thankyou1.1KViews0likes5CommentsComplex conditional summing
Hey everyone! how you doing? I have been now a month trying to make this logic work in dax but no solution. Cna anyone please help me with this? or even just say that power Bi will not be able of doing it happen? Here is the thing: I need to distribute evenly the stock of an item throught the orders of this item, in a way that the result is as shown in the table bellow: I need the stock to be distributed in a way that when its not enought to the order it will try to fit in the other order until the total stock is used. Use the stock amount of 21 for this example, you will see that the ones set as available, when summed will be exactly 21. The status column is the outcome that i need from the dax code. This is very hard, i don't even know if its possible; can anyone please helpe me with it? Thankyou a lot allready.10KViews0likes10CommentsCalculate sum of items based on date range and avaliable stock
Hey everyone, hope you all well. I'm new in the power bi, and having lots of trouble allready, can you help me with a situation? I need to set a status to the items of different orders based on its date and comparation between the stock and the quantity needed. Example: i have three tables called: date, with comun: date; orders, with columns: order number, item, quantity and date; and stock that has columns: item, quantity. they have for example the following data: Table date: date 01/01/25 02/01/25 03/01/25 Table stock: item quantity aaa 20 bbb 10 Table orders: Order num Item quantity date 111 aaa 20 01/01/25 111 bbb 10 01/01/25 222 aaa 10 02/01/25 333 aaa 20 03/01/25 333 bbb 2 03/01/25 i need a way of creating a graphic table to show, as i select a range of date in data segmentation for example: i select a range from 02 to 03/01, then based on the available stock, the status of the order number 222 will be: item aaa"available", and the other 333 item aaa will be "out" and the order 333 item bbb will be "available" but if i do not select any range and leave it all the dates selected, it will be: order 111, items aaa and bbb will be atatus "available" and the others will be "out". I also need a way to count all the "available" and "out" and i need to be able to select if i wanna se only the evailable or the out status. i don't know if i made myself clear, but could you help me please? Thankyou a lot.Solved2.6KViews0likes7CommentsHow to Sum and accurately summarize when conditions are in place
Hello Everyone, I am trying to have a Sum calculation based on several columns per row, there is an identifier that indicates that 3 columns should be included in the sum, and for any others only 2 columns. The issue I am having is that the row level calculation is correct and works perfectly, but when grouping by customers the identifier gets ignored, and the total sum aggregates the 2-column formula when in reality there is an internal item that has the "True" identifier. The second row on the example above shows the calculation when the identifier is "True", and yet the total amount does not show the actual sum of the 2 rows that are part of the customer revenue total. Perhaps using summarize will solve the issue but I don't understand how the syntax will work on my case. I have tried different measures and all end up the same, see them below Revenue = IF( SELECTEDVALUE('Carriers'[FRS_Product]) = TRUE, CALCULATE( SUM('Master Accounts Bound'[Renewal Net House Commission]) + SUM('Master Accounts Bound'[Agency Fees.amount]) + SUM('Master Accounts Bound'[Policy Fee]) ) , CALCULATE( SUM('Master Accounts Bound'[Renewal Net House Commission]) + SUM('Master Accounts Bound'[Agency Fees.amount]) ) ) --------------------------------------------------------------------------------------------------------------------------- Revenue X = SUMX('Master Accounts Bound', IF( SELECTEDVALUE('Carriers'[FRS_Product]) = TRUE, 'Master Accounts Bound'[Renewal Net House Commission] + 'Master Accounts Bound'[Agency Fees.amount] + 'Master Accounts Bound'[Policy Fee] , 'Master Accounts Bound'[Renewal Net House Commission] + 'Master Accounts Bound'[Agency Fees.amount] ) ) -------------------------------------------------------------------------------------------------------------------Solved1.4KViews0likes6Commentsmeasure is not showing total value in table visual
hi everyone i have created a measure that calculates sales agents commission based on his achievment % for each sales category. when i added the measure to a table visual, it's showing the the total value of the table visual as 0 instead of summing the commission values for each category. the total for measure 'new commission calculation' shoulde be 660 instead of 0 and the total for measure 'new agent incentive' should be 225 instead of 0Solved635Views0likes1CommentMeasure calculating Conditional SUM according to Values from another Table Not Filtering As Expected
I have a Production Table with Tons and Meters and I have an Asset Table with a Site Column and an Asset Group Type Column. I've got a requirement for a measure to show Tons for certain Asset Group Types and show Meters for other Asset Group Types. I've been able to do a DAX query that does this, but if I try and slice on Site, my values of production (tons and meters) don't slice, they only show the total. There is a relationship between the Production Table and the Asset Table on Site. Here is my DAX query for the calculated measure on my Production table. Tons/Meters = IF ( VALUES ( Asset[AssetGroupType] ) IN { "AssetType1", "AssetType2" }, SUM ( Production[Tons] ), SUM ( Production[Meters] ) ) Production Table: Site Tons Meters Site1 100 5 Site2 200 10 Site3 300 15 Asset Table: Asset AssetType Site Asset1 AssetType1 Site1 Asset2 AssetType2 Site1 Asset3 AssetType3 Site1 Asset4 AssetType3 Site2 Asset5 AssetType1 Site2 Asset6 AssetType2 Site3Solved703Views0likes2Commentssum total except for repeating rows
Hello community, I need a measure that sums follower_count and following_count (VALUE Column). I use some simple measures for this. However, this calculation should not calculate the repeating rows in the userid column. for example, I'm using this: User Reached = Sum(Single[follower_count]) + SUM(Single[following_count]) Thanks,Solved734Views0likes2CommentsMeasures Total Aggregation
Hello, I need support please to prevent Measures from aggregating when summing the total. To simplify, consider the below example where each of the below is stored in a different PowerBI table and hence SUMX hasn't been helping me: Products Total Due Volume Total Stocks Missing Volume Product A 10 0 10 Product B 5 0 5 Product C 0 90 0 Measure PowerBI Total 15 90 0 Correct Total 15 90 15 Given data is scattered across several tables in my model (and I cant really append them together), I used a simple IF ( Total Due Volume - Stocks > 0, 0, Total Due Volume - Stocks). The calculation works perfectly on product or line item level yet when PowerBI aggregates the total (either in tables or graphs), for the total specifically it looks at the total volume - total stocks which always gives the 0 (in bold above) since there is one outlier - product C in this case which has too many stocks- while what I am trying to achieve is make ti sum only the rows where missing volume is > 0 (equivalent of a sum if in excel) to get a sum of 15. Can you please let me know how? Note: Another workaround can be doing this as a new column in the table that houses the products instead yet I am opting for a measure because I need it to interact with a GenerateSeries slicer which displays different results as you move it up and down, something that doesn't work with tables unfortunately. Many thanks in advance!Solved2.5KViews0likes4Comments