Get result of difference of two columns in a matrix in third column - powerbi-desktop

Above is a matrix in PowerBI that displays the amount and target amount for various divisions. I want to calculate the different between actual amount and target amount and display it in a third column in the matrix. I tried creating a column that calculates the difference between these two columns in the data table. But the data displayed in the matrix is not what I wish for it to be. I want the matrix to display the difference between the target and actual amount based on the values in the matrix only (which are derived based on certain filters applied). I do not want to get the difference of all the values in the dataset.
I am completely new to PowerBI and any help for the same would be highly appreciated.

Simply, use calculate. The value is the result of the expression evaluated in a modified filter context. That means in your current filter/row context.
diff = calculate([Target] - [Amount])

Related

Spotfire: calculating difference between two rows in same column based on attributes in different columns

I am new to Spotfire and need help in getting the right expression for a calculated column.
My Data contains different subjects grouped in column ID. For every ID, Bodyweight was measured on different days. Days are given in column Day and stated as 1,2,3...
The last day is denoted by Last and Bodyweight measurements given in another column. Another column is present which is called Baseline. The Body weight measured is considered as baseline if the column contains a Y for that row.
I need to insert a calculated column, which will contain the difference between Body measurement measured on Day denoted Last and Body measurement marked by Y in column Baseline.
This should be done for every new ID. I am not able to figure this out. Could someone advise me on how to go about it?
Here is an example attached
So, the calculated column for Rita will give -4 (body weight at Last=56 and BodyWeight at baseline=56, so 52-56 =-4)
the sample data you provided is a little weird, particularly the [Day] column. if it's within your control, I suggest to use actual dates rather than a number/string here.
barring that, I was able to get your desired results, but it required two calculated columns: the first one will consolidate the [Day] and [Baseline] columns into a single column, and the second one contains your desired info.
column 1, which I called Day (int):
CASE
WHEN [Day]="Last" THEN 1000000
WHEN [Baseline]="Y" THEN -1000000
WHEN [Day]!="Last" THEN Integer([Day])
END
I picked a random high and low max to establish a chronological order. this will put 1000000 in place of "Last" (if you have any programs that are longer than one million days, you'll need to increase this number). the same for the [Baseline] column, but that value will be -1000000, which is presumably the lowest value you will ever see in this column. both of these are assumptions and may not work for your implementation. finally, in all other cases, the day number will be used.
column 2, which I called Diff:
Last([Weight]) OVER (Intersect([Name],LastNode([Day (int)]))) -
First([Weight]) OVER (Intersect([Name],FirstNode([Day (int)])))
the first line uses what's called an OVER expression to retrieve the first value for [Weight], ordered by [Day (int)], per [Name]. the second line gives the reverse of that, and so the difference is calculated as -4 (or whatever is appropriate).

Spotfire- calculated column with row ratios based on condition

I’m having trouble understanding if Spotfire allows for conditional computations between arbitrary rows containing numerical data repeated over data groups. I could not find anything to cue me onto a right solution.
Context (simplified): I have data from a sensor reporting state of a process and this data is grouped into bursts/groups representing a measurement taking several minutes each.
Within each burst the sensor is measuring a signal and if a predefined feature (signal shape) was detected the sensor outputs some calculated value, V quantifying this feature and also reports a RunTime at which this happened.
So in essence I have three columns: Burst number, a set of RTs within this burst and Values associated with these RTs.
I need to add a calculated column to do a ratio of Values for rows where RT is equal to a specific number, let’s say 1.89 and 2.76.
The high level logic would be:
If a Value exists at 1.89 Run Time and a Value exists at 2.76 Run Time then compute the ratio of these values. Repeat for every Burst.
I understand I can repeat the computation over groups using OVER operator but I’m struggling with logic within each group...
Any tips would be appreciated.
Many thanks!
The first thing you need to do here is apply an order to your dataset. I assume the sample data is complete and encompasses the cases in your real data, thus, we create a calculated column:
RowID() as [ROWID]
Once this is done, we can create a calculated column which will compute your ratio over it's respective groups. Just a note, your B4 example is incorrect compared to the other groups. That is, you have your numerator and denominator reversed.
If(([RT]=1.89) or ([RT]=2.76),[Value] / Max([Value]) OVER (Intersect([Burst],Previous([ROWID]))))
Breaking this down...
If(([RT]=1.89) or ([RT]=2.76), limits the rows to those where the RT = 1.89 or 2.76.
Next comes the evaluation if the above condition is TRUE
[Value] / Max([Value]) OVER (Intersect([Burst],Previous([ROWID])))) This takes the value for the row and divides it by the Max([Value]) over the grouping of [Burst] and AllPrevious([ROWID]). This is noted by the Intersect() function. So, the denominator will always be the previous value for the grouping. Note that Max() was a simple aggregate used, but any should do for this case since we are only expecting a single value. All Over() functions require and aggregate to limit the result set to a single row.
RESULTS

Use particular formula based on referenced value

I am working on creating a price list that uses calculated values to determine the price based on cost of good sold, area, and a few other things for some items.
There are different formulas used depending on the item type.
For example, prints would be calculated with an AREA multiplier type using the equation [#Multiplier]*[#Area] (referencing formatted table values, but they could also be typical references (f2*g2 for example)
So my question is, how could I set it so that a lookup of the multiplier type will reference a table that has the formula needed for that calculation.
I figured something like vlookup, but that either displays the equation itself, not the result, or doesnt work at all.
Currently, I have a big IF statement that works, but is a pain if I want to change the formula.
=MROUND(IF([#Mtype]='Multipliers 2'!$V$4,'Multipliers2'!W4,IF([#Mtype]='Multipliers 2'!$V$3,[#Multiplier]*[#Area]+40,IF([#Mtype]='Multipliers 2'!$V$5,2*[#[Cost of Goods]]+[#Multiplier], IF([#Mtype]='Multipliers 2'!$V$6,[#Area]*[#[Cost of Goods]]*[#Multiplier],[#Multiplier])))),0.5)
To Clarify, each product will have a multiplier type, along with data associated with the product that will be used for calculations:
So if I mark a product to use calculation A, the program should go look in a formula table, figure out what Calculation A is and then use those values to determine the result. If Calculation A = (Multiplier + 2*cost of goods sold), then it will look up the value in the multiplier column and add it to 2 x COGS.
Calculation B may be Multiplier * COGS and so on.
A problem I had last time I tried this a while ago was that even if I were to get the value to return some sort of result, I couldn't get the reference to change properly to correspond to the required row.
The data above is a small sample of what I'd be doing. Each product is part of a product type which has multiple variations in size, etc. So each product would reference a multiplier table which is used to calculate the final price, so if I want to change the prices for the entire group, all I'd have to do is change the value in the multiplier table, or the equation, and every corresponding product adjust accordingly.
The mtype would be controlled by the multiplier table. So I would like to set it so that if a particular mtype is used, the final calculation in the Price column will be determined by the formula listed.

Plotting an upper envelope function in Excel

I have got data points of a sound sample from Audacity which I exported to a .txt file and imported in Excel. Is it possible to plot an upper envelope function in Excel?
(In the end I have to determine the reverberation time, so the time in which the loudness decreases with 60dB.)
For a decaying oscillation such as this or a damped pendulum, the decay envelope can be found by looking at the difference between each sampled reading. You then need to see where the is a change in gradient from +ve to -ve. (or zero on one side). To do this some logical operators are used.
Method:
Consider data starting at column A row 5 for time and Column B row 5 for first data value.
Create a column which has the value minus the previous value. [ C6=B6-B5 etc.]
Next do a column for the gradient change giving a "flag" of 1 for a positive to negative or zero inflection [D7= IF (AND(C7>0,C6<=0],1,0)
This should produce a column of data that corresponds to the peaks.
In the next columns use the flag to get the original co-ordinates to display
[E7 =IF (D7=1,A7,"")] For time and [F7 IF(D7=1,B7,"")]
Copy this data using "Value" only in the paste option to yet another column.
Filter this to exclude the null data.
Beware of aliasing in data set.
Not the most elegant of solutions (and some steps can be linked -for clarity shown separately) but it works.
Tech99m

Ranking function

I am looking for some help regarding ranking. My spreadsheet has columns labeled as follows:
Tickers
P/E Rate of Change
P/B Rate of Change
Dividend Yield Rate of Change
P/Sales Rate of Change
I am looking to come up with a composite ranking that takes into account a tickers relative rank within each rate of change category. I tried this first by creating an additional 4 columns and using the formula as follows:
IFERROR(RANK(D4,$D:$D,1),"")
I believe this gives me a rank for the corresponding rate of change. However, for those cells that have either a blank or an error I want to use a median in calculating the tickers rank. I was then going to sum the ranks in another column to come up with my final ranking but that doesn't seem to be calculating correctly as I have blank rows returning rankings that don't make sense.
I think you are almost there.
For one column I would change what you have to
=IFERROR(RANK(D4,$D:$D,1),MEDIAN($D:$D))
Then simply expand to add all ranks together
=IFERROR(RANK(A4,$A:$A,1),MEDIAN($D:$D))
+IFERROR(RANK(B4,$B:$B,1),MEDIAN($D:$D))
+IFERROR(RANK(C4,$C:$C,1),MEDIAN($D:$D))
+IFERROR(RANK(D4,$D:$D,1),MEDIAN($D:$D))
+IFERROR(RANK(E4,$E:$E,1),MEDIAN($D:$D))
To avoid potentially large numbers you could use an average (same resulting rank, but potentially easier to understand) by slightly changing the formula to:
=(IFERROR(RANK(A4,$A:$A,1),MEDIAN($D:$D))
+IFERROR(RANK(B4,$B:$B,1),MEDIAN($D:$D))
+IFERROR(RANK(C4,$C:$C,1),MEDIAN($D:$D))
+IFERROR(RANK(D4,$D:$D,1),MEDIAN($D:$D))
+IFERROR(RANK(E4,$E:$E,1),MEDIAN($D:$D)))/5

Resources