Calculate column value by sub-column value - spotfire

I know this will require an advanced custom expression - I have 2 relevant columns, commodity and sub-commodity. A single event can have multiple commodities and sub-commodities. However, some commodities will naturally have more data about them. I don't want this to skew representation of the data.
I want to avoid that by counting values by their unique sub-commodity. In the below example, I want the bar chart to represent two instances of food for Event 1 (1 for meat, 1 for beverages) and one instance of garden for Event 2. How do I accomplish this?
EventID | Commodity | Sub-Commodity
1 Food Meat
1 Food Meat
1 Food Beverages
2 Garden Lawn Mower
2 Garden Lawn Mower

Thanks for the sample data. It helps in providing an answer.
You should be able to do this by using the UniqueCount() function. In this case the Y axis would be the expression UniqueCount([Sub-Commodity]). You can use custom expressions to input this or use the built-in drop down and select UniqueCount from the aggregation drop-down.
Take a look at the below image showing my implementation with a custom expression. Coloring is optional but I did so to show how it included your multiple sub-commodities and how they were counted (1 for Food=>Meat).
See below for an example with the drop-down:
Let me know if you have any questions or need further clarification. Thanks!

Related

Find a value depending on first, what type of event it is, second, what group is playing and, finally, where it is between two dates. Excel attached

I created a dataset to illustrate what I need help with. Its made up data so please pardon the strangeness.
I am trying to get a value from Col E "RESULT" and get it into Col K "Result", based on data like:
Tennis 1 01/01/2020
Tennis 2 04/01/2021
Basketball 2 25/05/2018
Squash 2 11/09/2019
Football 1 18/02/2016
The sport can vary so, that's the first variable;
The group that plays can vary so, that's the second variable. (I've only used 2 groups to make the dataset easier to create but assume there could be up to 6 or 7 groups playing);
Finally, the third variable, there's the date which falls between a start date and an end date (Col C and D).
I could use the lookup function to find where a date fits between two other dates but when you have 2 variables before hand, I have no idea how to deal with that.
BTW, just a final comment incase anyone asks, I don't know how to use VBA yet :/
Can anyone please help?

Efficiency question with excel using index match for each cell in a large sheet

I have a 4 types of customers, each pay in a different payment plan.
group 1 - monthly
group 2 - semi monthly
group 3 - bi weekly
group 4 - weekly
I have a sheet with a range of all the relevant payment dates for those group sorted in the right order in row 1
I would like that for each customer there will be a data validation list (group 1,group 2, group 3,group 4)
When selected the customer's row will populate on the correct dates according to his group number and the date the payment starts.
My work around to do that was to create 4 separate sheets for each group, auto populate from the correct date and run it for all customers in each group meaning you can see for John Doe what and when will be his payments in each group even though he is in group 3 for example. And a MAIN sheet where John Doe has group 3 selected where a MATCH and INDEX is running to find when he is supposed to pay and how much. The issue is that for 400 rows and 300 column this becomes heavy.
How would you go about solving that?
each cell looks like this in the MAIN sheet
=LET(mothlydate,Monthlyrd3!$BK$3:AAC$3,semidate,Monthlyth16!$BK$3:ZZ$3,namemonthly,Monthlyrd3!$BK79:AAC79,namesemi,Monthlyth16!$BK79:ZZ79,
IF(OR($BA96="Monthly 3 rd",$BA96="Semi-Monthly",$BA96="Monthly 16 th"),
IF((IF(IFERROR(INDEX(namemonthly,1,MATCH(GH$2,mothlydate,0)),"")+IFERROR(INDEX(namesemi,1,MATCH(GH$2,semidate,0)),"")>$AE96,$AE96,IFERROR(INDEX(namemonthly,1,MATCH(GH$2,mothlydate,0)),"")+IFERROR(INDEX(namesemi,1,MATCH(GH$2,semidate,0)),"")))=0,"",(IF(IFERROR(INDEX(namemonthly,1,MATCH(GH$2,mothlydate,0)),"")+IFERROR(INDEX(namesemi,1,MATCH(GH$2,semidate,0)),"")>$AE96,$AE96,IFERROR(INDEX(namemonthly,1,MATCH(GH$2,mothlydate,0)),"")+IFERROR(INDEX(namesemi,1,MATCH(GH$2,semidate,0)),"")))),
IF($BA96="Bi-Weekly 1",(IFERROR(INDEX(NewBiWeekly!$BK79:AAC79,1,MATCH(GH$2,NewBiWeekly!$BK$3:AAC$3,0)),"")),IF($BA96="Bi-Weekly 2",(IFERROR(INDEX(NewBiWeeklyTwo!$BK79:AAC79,1,MATCH(GH$2,NewBiWeeklyTwo!$BK$3:AAC$3,0)),"")),IF($BA96="Other",(IFERROR(INDEX(NewOther!$BK79:AAC79,1,MATCH(GH$2,NewOther!$BK$3:AAC$3,0)),""))))))
)
THANKS!!!
This is based on a purely textual analysis of your formula, since data required for a meaningful analysis hasn't been forthcoming:
the expression below occurs 4 times in your formula
IFERROR(INDEX(namesemi,1,MATCH(GH$2,semidate,0)),"")
as does this one
IFERROR(INDEX(namemonthly,1,MATCH(GH$2,mothlydate,0))
which means that, in the worst-case circumstances, one or both expressions are being evaluated on FOUR separate occasions - it would be sensible to consider making one or both of these named 'values' at the start of the LET() function, such that, in the worst-case cirumstances going forward, each would be evaluated only once.

excel PowerPivot Auto Calculated Measures & Columns

After looking at a few similarish questions I figured I needed something more specific so asking here. I will start by explaining the situation:
The Setup
I have a Store which sells Cakes, Cookies and Wine. I have the weekly sales data of each product sorta like this:
Product ID
Product Name
Quantity
Value
Week Ending
1
Ginderbread
2
£4
13/01/22
2
Chocolate chip
5
£25
13/01/22
3
Red Wine Bottle
1
£10
13/01/22
4
Sponge Cake
3
£9
13/01/22
Currently every week's data is stored within the same table, with me using a Week filter to show only the week i'm interested in.
Using this Data I created PivotTables that shows the sales of each category, with the ability to drill down to show the specific products. Table looks something like this:
Category
Quantity
Value
Cakes
2
£4
Cookies
7
£29
Wine
1
£10
The issue
I now want to stick in a new calculated column that shows the Value as a %. E.g The total value for the previous table was £43, so Cookies is about 67%. If I drill down, it would show the Chocolate Chip record as 80% and Gingerbread as 20%
I imagine doing this would be easier if each individual week's data was on a different table, but I got a lot of weeks and I also want to do tables showing the sales for over a period of time. Plus I don't know of a way to merge the "value" and "quantity" columns, etc instead of having 1 for each week being shown.
any advice would be appreciated
Create an extra column in the source table (prior to filtering) entitled "perc" calculated as the corresponding value for each row divdied by the total value across all rows (se pic. / eqn. for first row below) --
=E2/$E$6
No calculated fields required - just include perc as the mesaure of interest in your pivot table, with value setting as 'sum':
The reason why this worked is because of the common denominator - which allows one to sum ratios on a 1:1 basis.
Devising a calculated field using the standard 'fields, items & sets' functionality for ordinary pivot tables would not be feasible / possible as far as I am aware. You would need to move into the realm of power pivots and data models - which is not too complicated (readily accesible directly from the field list per below) - however, I see this as unnecessary complication for the task at hand.
Side notes:
Using table names in your functions is sometimes more convenient when entering, albeit may appear tricky at first when reviewing - first eqn above becomes:
=[#Value]/Table1[[#Totals],[Value]]

OR criteria with DAVERAGE

Given a large number of entries like the following:
type quantity
apple 3
orange 6
pear 2
pear 2
orange 1
...
I know I can create a pull down menu where I can select any type, say 'apple' or 'orange' and get the average quantity for that specific type: to do so, I use daverage where the criteria is a cell with data validation (i.e. whose content is controlled by a pull down menu).
But what I would also like to have in my pull down menu is an entry 'apple or orange' which when selected gives me the average quantity for apple and orange combined.
I know I can use daverage to compute that number but I don't know how to use that in combination with a pull down menu to achieve my final goal so that by simply modifying the content of cell controlled by a pull down menu, I can obtain the average for either orange, or apple, or orange and apple combined. Is there a way?
I'm posting an answer regardless because though not suitable for you it may be suitable for others in a similar (but not identical!) situation:
Including blanks in data validation can have drawbacks but if applied only to the selection criteria (highlighted yellow) this can be advantageous (two blanks in A2:A3 and the overall average is shown). Treating apple and orange separately rather than as orange-apple is simpler (does not require your workaround) and flexible – any pair (rather than pear!) could be chosen without extending the validation list.
Following pnuts' suggestion and the very same example data: I added a column isAppleOrOrange, computing yes or no using a following formula like this:
=IF(OR(A6="apple",A6="orange"),"yes","no")
This way, if you specify 'yes' in B2, you get the average for apple + orange combined. You can still specify any fruit you want in B1 to get the average for a specific fruit alone but need to make sure isAppleOrOrange is left blank in that case:

How should I design an data table that has six or more variables?

The situation is akin to the following:
Assume I am a store selling fruits, I would like to record the costs of each type of fruit. Assume the customer has specific tastes, and they can differentiate everything.
A fruit can be an orange, apple,
pear, or peach
It could be n days fresh from the vendor
The fruits come from different countries and have different taxes for export
Fruits are also valued by weight
Fruits could have handling requirements (Fridge,water sprigs)
Fruits could also be valued just because of different origins
One idea is to do what is done in some industries, assign a unique product code for each variation: e.g. Orange5dayfreshAustralia200gfridgeSydney
This however, would be a HUUUUUGE long list of values, and should any costs change, it would be hell to search for Apples from Turkey that are 200 grams have now 20cents more export tax. Adding new variables would also massively mess up the whole table and require much recoding.
The other way is to assume a standard orange, peach, apple and pear and different weight(2 dimensional table). On other tables, prepare a list of cost savings/increase for any given deviation. (Law of probability should show me I have 80% "standard" fruits, and 20% niche fruits from funky places having funky costs)
E.g. a 1 day fresh orange compared to a standard 4 day fresh orange is 50cents more, regardless of weight.
(Yes, this means the primary table would need to have at least one variable that dont affect the others)
Final constrain: The data entry is done by hired hands, needs to be simple to enter in Excel. The programing can be difficult, but not the general interface.
Any suggestions?
If the information needs to be encoded in the product code, you can use subcodes to build a complete product code.
Type of fruit
AP - Apple
OR - Orange
PR - Pear
PC - Peach
You can use Country Codes for the country, and other subcodes for handling and origin.
EXAMPLE:
AP06BR145HROR
is a Brazilian apple, six days old, weighing 145 grams, with HR handling and OR origins.
Obviously you would need a lookup table and foreign keys for each of the code types.
You seem to have twigged your problem - your data structure is wrong.
Your list is really a collection of attributes that apply to each "batch" of stock you purchase - except perhaps for "n days fresh" where the attribute is the difference between the attributes of date picked and date delivered.
So what you really want is a data table for each attribute type, and then a transcation data table where you add the attributes. The input is a form where the attributes are loopups.
You also need your pricing rules in a table, which you can use to calculate prices.
If your transaction table records both sales and purchases then you can filter on the attributes to report by any combination you like.
But the bit that interests me is how you work out how old the fruit is you are selling. You might know from the paperwork that you have purchased x oranges from Spain on one day and y oranges from Italy on another day, but in the box oranges are just oranges - so how do you tell which are which? Or are you planning to use a FIFO or LIFO scheme?

Resources