I have two tables, Products and Ingredients. I want to take a the weighted average of all Products with the same Code.
Here is the Ingredient Table
And Here is the Product table where I am using a formula to calculate Avg Price.
Here is a formula that I used but I have no idea how to change it to only calculate the averages for items with the same code. I thought about AVERAGEIFS but not sure how to implement it into the formula.
=B2 * SUMPRODUCT(Ingredient!D1:D6, Ingredient!C1:C6)/SUM(Ingredient!C1:C6)
You could do:
= B2 * SUM( Ingredient!$C$2:$C$6 * Ingredient!$D$2:$D$6 * (Ingredient!$B$2:$B$6=C2) )
/ SUM( Ingredient!$C$2:$C$6 * (Ingredient!$B$2:$B$6=C2) )
Related
Using O365
In F2, find sum for Type "Revenue" and Group "A" using the Amount & Allocation % Tables.
F2 = $10,000 * 10 % + $15,000 * 20% = $4,000
10% = ACCT + A
20% = BRRT + A
I'm trying to avoid adding helper columns to the Amount Table such as:
Using =XLOOKUP(Table1[#[Dept]:[Dept]]&Table1[[#Headers],[A]],Table2[[Dept]:[Dept]]&Table2[[Group]:[Group]],Table2[[Alloc%]:[Alloc%]],0)*Table1[#[Amount]:[Amount]]
So far, I am stumped about how to proceed without the use of Helper Columns and a SUMIFS in J2. This method would use too many resources given my dataset size (200k rows).
Any ideas? SUMPRODUCT with SUMIFS? Power BI table links and DAX? TIA
you are on the right tract with SUMPRODUCT and SUMIFS:
=SUMPRODUCT(SUMIFS(Table1[[Amount]:[Amount]],Table1[[Type]:[Type]],Table4[#[Type]:[Type]],Table1[[Dept]:[Dept]],Table2[[Dept]:[Dept]])*Table2[[Alloc %]:[Alloc %]]*(Table2[[Group]:[Group]]=Table4[[#Headers],[A]]))
Table1 = A1:C5
Table2 = A7:15
Table4 = E1:I3
I am working on a matrix in Power BI and I am not figuring out how to sum each column recursively until the total:
And this should be the resulting matrix (as an example, rows):
Some clarifications:
The months (columns) are dynamically generated based on the transaction month. I could filter the data to get the same data for only three months.
"Nombre proveedor" stands for "Vendor name".
I don't care about "Total" row.
These are my values:
So, I think I should create a measure with DAX to replace "Accounting Balance" to sum the previous column (month) or show nothing (to avoid zeroes).
Searching on internet I found several sites to get the running totals by rows, but not by columns.
Any suggestions?
Try Something like this:
Maesure =
CALCULATE (
[Accounting Balance],
FILTER (
ALL ( 'table' ),
'table'[Transaction month] <= MAX ( 'table'[Transaction month] )
)
)
This should be a fairly easy question for Power Pivot users since I'm a newbie. I am trying to do the following. After pivoting a table I get a crosstab table like this
rating count of id
A 1
B 2
Grand Total 3
You can imagine the original table only has two columns (rating and id) and three rows (1 id for A and two different id's for the B rating). What DAX formula do I have to write in order to create a measure that simply shows
rating percent of id
A 1/3
B 2/3
Grand Total 3/3
By 1/3 of course I mean 0.3333, I wrote it like that so that it is clear that I simply want that percent of id is the count for each rating divided by the total count. Thank you very much
You need to divide the count for each row by the total count.
DIVIDE (
COUNT ( Table1[ID] ),
CALCULATE ( COUNT ( Table1[ID] ), ALL ( Table1 ) )
)
For this particular calculation, you don't have to write DAX though. You can just set it in the Value Field Settings.
Summarize Value By : Count
Show Values As : % of Column Total
I have a table(Data_all) that calculates daycount_ytd in one table.
[Date] is in Date Format.
[Fiscal Year] is just year. eg: 2016
Calculated Column
daycount_ytd=DATEDIFF("01/01/"&[Fiscal Year],Data_all[Date],day)+1
Im trying to create a measure that refers to this Calculated Column
Measure:
Amt_X Yield %:=[Amt X]/([Amt Y]/365* (Data_all[DayCount_YTD]))
I get the error that Data_all[DayCount_YTD] refers to a list of values.
How do i filter the expression to get a single value without using a aggregation function eg:(sum, median)?
Or perhaps, is there another way to achieve the same calculation?
You've arrived an a fundamental concept in DAX and once you've worked out how to deal with it then the solution generalises to loads of scenarios.
Basically you can't just pass columns into a DAX measure without wrapping them in something else - generally some kind of mathematical operation or you can use VALUES() depending on exactly what you are trying to do.
This measure will work OK if you use it in a PIVOT with the date as a row label:
=
SUM ( data_all[Amt X] )
/ (
SUM ( data_all[Amt Y] ) / 365
* MAX ( data_all[daycount_ytd] )
)
However you will see it gives you an incorrect total as it is in the latest for the entire thing. What you need is a version that iterates over the rows and then performs a calculation to SUM or AVERAGE each item. There is a whole class of DAX functions dedicated to this such as SUMX, AVERAGEX etc. You can read more about them here
It's not totally clear to me what the maths behind your 'total' should be but the following measure calculates the value for each day and sums them together:
=
SUMX(
VALUES(data_all[date]),
SUM(data_all[Amt X]) /
(SUM(data_all[Amt Y]) / 365 * MAX(data_all[daycount_ytd]))
)
I need to Aggregate a number of multiplications which are based on the Row and Columns context. My best attempt at describing this is in pseudo-code.
For each cell in the Pivot table
SUM
Foreach ORU
Percent= Look up the multiplier for that ORU associated with the Column
SUMofValue = Add all of the Values associated with that Column/Row combination
Multiply Percent * SUMofValue
I tried a number of ways over the last few days and looked at loads of examples but am missing something.
Specifically, What won't work is:
CALCULATE(SUM(ORUBUMGR[Percent]), ORUMAP)*CALCULATE(SUM(Charges[Value]), ORUMAP)
because you're doing a sum of all the Percentages instead of the sum of the Percentages which are only associated with MGR (i.e., the column context)
Link to XLS
One way of doing that is by using nested SUMX. Add this measure to ORUBUMGR:
ValuexPercent :=
SUMX (
ORUBUMGR,
[PERCENT]
* (
SUMX (
FILTER ( CHARGES, CHARGES[ORU] = ORUBUMGR[ORU] ),
[Value]
)
)
)
For each row in ORUBUMGR you will multiply percent by ....
the sum of value for each row in Charges where ORUBUMGR ORU is the same as Charges ORU. Then you sum that product.