Excel formula where certain combinations of cells would return a value - excel

I'm creating a stakeholder map and I have two columns with two possible entries for each
Power | Interest | Strategy
Power and Interest can be either High or Low
So I am trying to get a strategy to return a value based on whether Power or Interest is one of those two combinations as an example:
Power = High, Interest = High, Strategy = Manage Closely
Power = Low, Interest = High, Strategy = Keep Informed
Power = Low, Interest = Low, Strategy = Monitor
Power = High, Interest = Low, Strategy = Meet Their Needs
Can someone help me with this formula?

Make a new column where you concatenate Power and interest.
A B C D
1 Power Interest Concat Result
2 High Low HighLow
3 High High HighHigh
Then somewhere down in the excel (or in another tab) make a relationship between inputs and outputs
A B C D
1000 Power Interest Concat Result
1001 High High HighHigh Manage Closely
1002 High Low HighLow Kep Informed
1003 Low High LowHigh Monitor
1004 Low Low LowLow Meet Their Needs
finally use the following formula in the cell D2 and slide it down to all your rows
=VLOOKUP(C2,$C$1001:$D$1004,2)
Where C is the concatenated column, C1001:D1004 is the relationship table location.
You can then hide the column C if you wish.

So, a long way is to use if() with AND() like so:
IF(AND(B1="high",D1="High"),"Manage closely",IF(AND(B1="Low",D1="High"),"Keep informed",IF(AND(B1="Low",D1="Low"),"Monitor",IF(AND(B1="high",D1="Low"),"Meet their needs"))))
But a table with vlookup() is easier to control as per the other answer. However, this does not use a helper column...

I tried this formula and it worked for me:
=IF(AND(A2="High";B2="High");"Manage Closely"; IF(AND(A2="Low";B3="High");"Keep Informed"; IF(AND(A2="Low";B2="Low");"Monitor"; IF(AND(A2="High";B2="Low");"Meet Their Needs";0))))
Drag down/Copy and paste the formula under the Strategy Column and it should turn out like this:

Another solution:
You can use built-in function below after saving your file as an .xlsm file and saving the code in a new module in file:
Function myStrategy(power As String, Interest As String) As String
If LCase(power) = "high" And LCase(Interest) = "high" Then
myStrategy = "Manage Closely"
ElseIf LCase(power) = "low" And LCase(Interest) = "high" Then
myStrategy = "Keep Informed"
ElseIf LCase(power) = "low" And LCase(Interest) = "low" Then
myStrategy = "Monitor"
ElseIf LCase(power) = "high" And LCase(Interest) = "low" Then
myStrategy = "Meet Their Needs"
End If
End Function

Related

How do I calculate the number of years to target in Microsoft Excel

If I have an average YOY growth of say 2.5%, current year sales of $500,000, and target sales of $1,000,000. Is there a way to calculate the number of years until I hit my target (assuming a continued YOY growth rate of 2.5%), without calculating each additional years's sales on a different row?
You can use the NPER function for this:
=NPER(Growth,0,currentSales,-targetSales)
Note that this gives the same result as #Dominique, but is using a built-in Excel function.
Also, by virtue of the nature of Excel financial functions, the signs for the current and future Sales need to be different.
There's a simple formula for this:
Money_end = (1+r/100)^Y*Money_begin
Where:
Money_begin = the starting amount of money, in this case 500000.
Money_end = the finishing amount of money, in this case 1000000.
r = the percent ratio, in this case 2.5.
Y = the amount of years, which you are looking for.
So, your question comes down to solving this equation:
1000000 = (1+2.5/100)^Y * 500000
2 = 1.025^Y
Y = log(2)/log(1.025)
If you want this to be solved by Excel, you might use the formula and use the Solver basic Excel feature for coming up with the same (but numerical instead of analytical) result.

How to remove duplicates from individual powerquery columns without removing entire rows

I have a data table that records cost savings data and I have 1 row per project. This has overall project type data such as annual spend, annual savings, etc. but also has the months the savings fall into. To pivot on this data, I converted it to a table with PowerQuery but some columns repeat such as annual spend for each month where there are savings so I might get 10 rows for savings which is correct, but the annual spend is duplicated 10 times. Can I remove duplicates in just those columns retaining the other data.
I have searched and tried various solutions but haven't found one that works. I am not set on data table format, so am open to anything.
Below is a sample of the data
Sample of PowerQuery
As you will see, Baseline Spend, Negotiated Spend, Savings Amount are all shown for each row and I need to use these in a pivot/slicer.
Any help would be appreciated.
Regards,
Keith
I think one solution might be to "only keep the first1 annual spend per project". More abstractly, "only keep the first value in column(s) X per column(s)Y".
Below is some mock/dummy data. I only want to keep the highlighted values in my annual spend column (as the highlighted values are the first "annual spend" figures per "project").
This is the M code I'm using to achieve this. (To try it, open the Query Editor > Advanced Editor (near top right) > copy-paste code below to there > OK).
let
OnlyKeepFirstValueInColumn = (someTable as table, columnsToNullify as list) as table =>
let
firstRow = Table.FirstN(someTable, 1), // This assumes first row contains a non-blank value.
remainingRows = Table.Skip(someTable, 1),
loopAndNullify = List.Accumulate(columnsToNullify, remainingRows, (tableState, currentHeader) => Table.TransformColumns(tableState, {{currentHeader, each null}})),
combined = firstRow & loopAndNullify
in combined,
FirstValueOfColumnsPerGroup = (someTable as table, groupByColumns as list, columnsToNullify as list) =>
let
group = Table.Group(someTable, groupByColumns, {{"toCombine", each OnlyKeepFirstValueInColumn(_, columnsToNullify), type table}}),
combined = Table.Combine(group[toCombine])
in combined,
aggregatedTable = Table.FromColumns({Text.ToList("aaabbbccccdddeeefg"), List.Repeat({1000}, Text.Length("aaabbbccccdddeeefg"))}, type table [project=text, annual spend=number]),
transformed = FirstValueOfColumnsPerGroup(aggregatedTable, {"project"}, {"annual spend"})
in
transformed
The important bit to understand is this line:
transformed = FirstValueOfColumnsPerGroup(aggregatedTable, {"project"}, {"annual spend"})
in which you should replace:
aggregatedTable with whatever variable/expression contains your table
{"project"} with the name of your "project" column (keep the curly braces {} though as they let you pass in several columns if needed)
{"annual spend"} with the names of whichever column(s) you want to keep only the first value in (keep the curly braces {})
This is what I get (which I think is similar to what you want):
1To keep things simple, we'll say "first" here means the value in the first row. It could have meant "first non-null value" or "first value satisfying some particular condition or logic", but your data suggests the simpler definition will work okay.

How to get cell value from another excel sheet based on multiple list conditions

I apologise if this comes across as a newbie query, but I have been stumped by this for some time.
I am building an excel spreadsheet for my staff to be able to compare stock listings easily and automatically based on reference data held in a different sheet within the same workbook.
The difficulty is that I want to pull this reference data based on the values chosen from a total of 6 conditional drop down lists I have created.
Based on what is selected, the values on say Sheet 1 will display the relevant values from Sheet 2 automatically (i.e. if one of the list options is changed, the "results" will update with the associated data automatically).
I have tried using lookup functions, arrays and nested if functions, but I have been unable to get it to work properly - probably due to my own lack of depth of knowledge for this type of coding. As such I am looking for advice about the best way to code this function requirement.
The format of what I am trying to do is this:
Sheet 1 - The 'GUI'
This sheet has the dropdown lists and the "displayed results" section
dd1 - State (6 options)
dd2 - Product Type (4 options)
dd3 - Product Brand (3 options)
dd4 - Product variation 1 (eg model) (say, 2 options)
dd5 - Product variation 2 (eg colour) (5 options)
dd6 - Product variation 3 (eg size) (3 options)
Sheet 2 - Reference data
Table 1 - ACT products and variations
Table 2 - VIC products and variations
Table 3 - NSW products and variations etc and so on...
Based on choices above in Sheet1, I want the product & price to be listed in cells below. Currently I have conditional functions listing the avail options based on the choice made for the prev list working fine.
I need it so that:
IF dd1 = "ACT" AND dd2 = "Mobile" AND dd3 = "Apple" AND dd4 = "iPhone" AND dd5 = "white" AND dd6 = "128Gb"
Then
The results cell, say Sheet1!C10, will reflect the price of the item based on a table of data lists in Sheet2 (say for eg the listed value is in Sheet 2, Cell A5)
But if say the list choices change, eg dd3 was changed to "Samsung", then the lists will auto update because of the conditional formatting already; but I then want the results to be updated accordingly (eg the price listed based on the new choices will then reflect Sheet2!B3).
Because of the many options and variations, there are many tables in Sheet 2 for reference, so the 'IF' statement to cover all these options would be massive and convoluted.
Is there a relatively concise way of writing vb code for this function to suit?
My current code under the worksheet_change sub
If Range("D10").Value = "ACT" And (Range("D11").Value = "Mobile" And (Range("D13").Value = "Samsung" And (Range("D14").Value = "S7") And (Range("D15").Value = "Black") And (Range("D16").Value = "128"))))) Then
Sheets("Sheet2").Range("F20").Value = Sheets("Sheet4").Range("C5").Value2
Sheets("Sheet2").Range("F29").Value = Sheets("Sheet4").Range("C6").Value2
ElseIf Range("D10").Value = "ACT" And (Range("D11").Value = "Mobile" And (Range("D13").Value = "Samsung" And (Range("D14").Value = "S7") And (Range("D15").Value = "Black") And (Range("D16").Value = "256"))))) Then
Sheets("Sheet2").Range("F21").Value = Sheets("Sheet4").Range("C8").Value2
Sheets("Sheet2").Range("F22").Value = Sheets("Sheet4").Range("C9").Value2
Sheets("Sheet2").Range("F29").Value = Sheets("Sheet4").Range("C10").Value2
'and so on. With all the variations, there's prob going to be approx 20+ elseif statements.
End If
Ive only pasted 2x sections for the purpose of this request. I can copy it down or adjust the code accordingly for each option.
Ive not used nor written arrays before (successfully i.e.) so I have no clue/understanding if that is a better way, but i have written vba for basic functions and macros before; but im open to learn.

Excel VBA - Change cell value via another cell?

So VBA is completely new to me. I come from a C# background.
Currently creating an order form, whereby I can input the total amount I require of an object and then the price is calculated in a different cell.
However I also want the price to change based off amount thresholds for that object.
Say for example 0 - 100 will cost £2.50 so I expect the answer to be anywhere within that range is multiplied by 2.50. Meanwhile if the amount exceeds 100 and becomes 120 I want the object price to now reflect £2.30 and proceed to multiple the 120 by £2.30.
I've noticed a few tutorials on line but they don't exactly explain how I might be able to achieve the above. Wondering if anyone can point me in the right direction?
Non VBA Soluion
If you build a table with the bottom and upper thresholds for a price, you can simply use a VLOOKUP and return the approximate match.
In photo, Column C is the output from the equation that is shown in Column D
VBA Solution
You can also use a simple UDF. Paste the code inside a Module and then you can call the function PRICEINDX from a cell just like any other equation. You can either manually type in a value like PRICEINDX(164) or select a cell that has the value to be tested like PRICEINDX(A1)
You can also set up more complex thresholds easily by using Select Case
Option Explicit
Public Function PRICEINDX(Target As Double) As Double
Dim ans As Double
Select Case Target
Case 0 To 100
ans = 2.5
Case 101 To 200
ans = 2.3
Case 201 To 300
ans = 2.1
Case Is > 300
ans = 2
End Select
PRICEINDX = ans
End Function

How can I order a PivotTable's ranges by the value in a particular cell (Aspose Cells)?

I need to order the ranges (each range covers four rows) by a value in one of that range's cells. This is how the first bunch of data looks:
I need to order these by the value in the cell at the juxtoposition of "Sum of TotalPrice" and "Grand Total". So in the data shown, the order should be:
ASPARAGUS, STANDARD 11/1#
LETTUCE, SPRING MIX 3#
ASPARAGUS, LARGE 11/1#
LETTUCE, ROMAINE HEARTS 48 CT
CUCUMBERS, ENGLISH (SDLS) 12-14 CT
TOMATOES, 5x6 LOOSE X-LG 25#
CARROTS, BABY PEELED W/TOPS 5# (IMPORT)
TOMATOES, CHERRI 12/1 PT
How can I do that, with Aspose Cells?
In Excel Interop (which is untenable for some of these reports, as it will not even generate the larger ones, even after hours, whereas Aspose Cells can generate them in several minutes), the code is this:
// These two lines don't seem that they would do so, but they do result in the items
// being sorted by (grand) total purchases descending
var fld = ((PivotField)pvt.PivotFields("Description"));
fld.AutoSort(2, "Total Purchases");
As the comments indicate, why this works is a mystery to me, and surely the way to do this in Aspose Cells, and probably more grokkable, but just how is the question.
UPDATE
The following code:
pivotTable.DataFields[0].DisplayName = "Total Packages";
pivotTable.DataFields[1].DisplayName = "Total Purchases";
pivotTable.DataFields[2].DisplayName = "Avg Purchase";
pivotTable.DataFields[3].DisplayName = "% of Total";
pivotTable.RowFields[0].ShowInOutlineForm = true;
pivotTable.RowFields[0].ShowCompact = true;
PivotField field = pivotTable.RowFields[1];
field.IsAutoSort = true;
field.IsAscendSort = false;
field.AutoSortField = 1; // 0 based indexed position in the PivotTable.DataFields
pivotTable.PivotTableStyleType = PivotTableStyleType.PivotTableStyleLight16;
pivotTable.RefreshDataFlag = true;
pivotTable.RefreshData();
pivotTable.CalculateData();
pivotTable.RefreshDataFlag = false;
...but it did not work for me; it failed with, "You can't operate the field" on this line:
field.IsAscendSort = false;
We need your template Excel file (if any), output Excel file (containing Pivot Table) by Aspose.Cells APIs and an Excel file that you may manually create in Ms Excel that should contain the PivotTable with your desired order set for the underlying ranges. We recommend you to follow up your Aspose forum thread.
I am working as Support developer/ Evangelist at Aspose.

Resources