Recursive DAX Formula help needed - dax

I have tried to do some research, but cannot find the answer I am looking for. I have a table that has recipes. Some recipes use portions of other recipes in the same table. See below. P-salt is a house seasoning, and it is used in other recipes. Some recipes go as far as 3-5 iterations deep before finding the original ingredient.
Picture of dataset
Batch Item
Ingredient
Amount
UOM
Batch Yield
Batch UOM
Item Cost
Marinade
Buttermilk
64
floz
68
floz
3.47
Marinade
P-Salt
4
floz
68
floz
1.29
Fillet
Chicken Fillet
25
Each
25
Each
1.74
Fillet
Marinade
68
fl oz
25
Each
1.74
P-Salt
Black Pepper
8
floz
64
floz
3.55
P-Salt
Granulated Garlic
16
floz
64
floz
7.88
P-Salt
Paprika
8
floz
64
floz
3.71
P-Salt
Onion Powder
8
floz
64
floz
5.08
P-Salt
Salt
16
floz
64
floz
0.35
You will see that P-Salt is involved in other recipes, including the Marinade. The marinade is used in turn as a part of the fillet recipe. I am trying to create a measure that uses this table to find out (for example) how much Black Pepper would be used in the full recipe for marinated chicken. Math says it should be 68 (total ounces in final recipe) / 68 (total yield from the recipe that matches) * 8 (amount of black pepper that yields the full batch). I will then use the amount used in each recipe to calculate a total cost in each recipe. The two bolded cells in the table above shows the calculation I am struggling to make ultimately.
I have it working now with calculated columns to get to the second layered recipe and sum that together. I cannot figure out how to make it keep digging deeper until it doesn't need to. Most recipes will only go one layer deep, but many will need to go beyond that. How can I get a measure that digs x layers deep to find the amount of the base ingredient used?

Related

How to sample data in R, within specific amount of cases

I'm trying to resample data, but I don't know how to tell the "sample" function to do it within a condition or specific amount of cases.
The objective is to resample a statistic from a Wald test, balancing the amount of cases of two conditions: control vs the treatment, as the original data is unbalanced.
For this I have 48 "control_IDs" (corresponding to 228 observations across time), and 326 "treatments_IDs", corresponding to 4531 observations. The ID corresponds to the individual subject to the treatment or not.
Overall, one part of the structure is pretty straightforward, and I'm able with the attached code to sample 228 from the 4531 observations of my "treatment", to run the model and Wald test.
The problem that I have is that when I run the code, the 48 IDs of the "control" are fix, but the ones from the "treatment" are not. So I end with 228 observations of 48 control_IDs, but 228 observations of a varying amount of "treatment_IDs" (from ~60 to ~180) depending on the run.
Any idea of how to properly code that the random 228 treatment observations comes from a random sample of 48 "treatment_IDs"?
Thanks!
df2<-subset(original_df,treatment =="control")
resampling<-replicate(5000,{resampled.data=sample(1:nrow(df), 0.0504*nrow(df), replace=F)
x1=df[resampled.data,]
x2=rbind(x1,df2)
Model= glmer(response ~ treatment*var1*var2+var3
+ (1|ID), data=x2, family="binomial",
control=glmerControl(optimizer="bobyqa", optCtrl=list(maxfun=2e5)))
Anova(Model)[1,-1:-2]
})

which machine learning algorithm and tool to use for suggesting which bin(s) to use, and the quantity?

I am new and this is my first question here. I hope this is the right place to ask this.
I am looking for a machine learning tool and algorithm that I can use to suggest which bins to use and the quantity from each chosen bin. For example, demand for a particular item can be fulfilled by using any of the 4 bins (bin 1 ~ 4) and multiple bins can also be used. Based on the historical pattern, I'd like to suggest which bins to use and quantities as well. Here is a sample data. Given the Order quantity and initial quantities of the bins, I'd like to suggest which bin to use and how much (which are the 'used quantities').
item
Order qty
packing_size
Initial qty
used qty
bin1
bin2
bin3
bin4
bin1
bin2
bin3
bin4
A
500
20
150
350
100
250
100
150
100
150
A
100
20
80
10
50
10
40
10
40
10

Is this a classification problem or regression problem? And what algorithm can be applied to solve it?

Let's say we are selling 3 different flavors of juice (orange, apple and grape), and customers purchase several bottles of juice for a group of people. For the sake of this question, let's assume they select flavors depending on various input data such as season, weather, temperature, etc.. There can be many inputs but let's limit the inputs to 4 in this example. Here is an example of their purchase history:
Order qty
Input_1 (season)
Input_2 (weather)
Input_3
Input_4
orange
apple
grape
50
summer
sunny
78
adult
20
0
30
30
winder
rainy
35
children
20
10
0
75
spring
cloudy
50
both
30
30
15
What machine learning algorithm can predict how many of each flavor a customer would purchase given the input parameters? Notice that the total of 3 flavors must add up to the order quantity, and number cannot be less than zero.
It is a regression problem.
You can solve it easily with deep learning: just one-hot encode the categorical features and please normalize numerical values.
X is features 0 to 5 and y is orange apple and grapes features.
Then you can train and predict a deep neural network model.
Tensorflow and Pytorch are good example of deep learning libraries

Generate a team from a list of unique players based on priority number. 3 Arrays of signups for different role

Im trying to create an application that would form a team of 4 people in a shooter game.
There are 3 roles for 4 players. We need 2x assault, 1x sniper and 1x medic in a team.
I would be choosing players from 3 arrays, each array contains signups for that role (playername and priority number). Players can signup for multiple roles.
Sniper[0] John 100
Sniper[1] Mort 91
Sniper[2] Stef 70
Medic[0] Jerry 92
Medic[1] Mort 91
Medic[2] Jambo 19
Assault[0] Jerry 92
Assault[1] Haler 91
Assault[2] Gowgow 79
Assault[3] Jambo 19
This is how the 3 arrays would look like.
Selection in this case should be:
Sniper - John 100
Medic - Mort 91
Assault1 - Jerry 92
Assault2 - Haler 91
Application should always try to select people with highest priority for available roles.
If anyone could at least point me in the right direction on how to solve this issue. Im really stuck here as I have no idea how to do it and I don't know what to search for online either, to learn.
I solved my selection problem with a "Hungarian algorithm or Munkres".

Calculating Version QR Codes

How many total bits are sorted in the grid of a Version 4 QR code?
All I could find is that Version 4 is 33 rows by 33 columns. Please help, thank you!
Assuming in "33 rows by 33 columns' you mean that there are 33 pixels in both directions, you would simply multiple those two numbers together, and then multiply the result by 8 (as there are 8 bits in a byte, and one byte per pixel).
As such, you're probably looking for 33 * 33 * 8.
That would be 8712 bits.

Resources