Compare successive rows Alteryx - alteryx

I have a spreadsheet with order item in column A, order quantity in column B, order start date in column C, and order finish date in column D. What I would like to do is treat orders on consecutive start dates for the same item as one single order. So until there is at least one days break between order start dates for an order item, treat it as one single order. Then I need to count the orders, sum the order quantities and calculate the average gap in days between orders (gap between order finish date and the next order start date). So if an order item was ordered on the 1st, 2nd, 3rd and 4th of March, and then again on the 10th and 11th of March, and then again on the 20th March (with all orders having the same start and finish date), there would be 2 gaps, which the average gap being 7.5 days ((6+9)/2). So the input and output will look like this;
Any help would be much appreciated. Many thanks!

Discussion...
The fields I've defined are OrderItem, OrderQty, OrderStartDate, and OrderEndDate, plugging in values identical to those you provided.
The Select tool just forces OrderQty to Int32
MultiRow Formula, creates new Int32 variable Gap using this expression:
IIF(IsNull([Row-1:OrderStartDate]), 1, DateTimeDiff([OrderStartDate], [Row-1:OrderStartDate],"Days"))
First Summary tool:
Group By OrderItem ...
Group By Gap ...
Sum OrderQty to new output field OrdersPerGap
a. Top avenue Summary tool:
Group By OrderItem ...
Sum OrdersPerGroup to output field name OrderQty ...
Count OrderItem to output field name NumOrders
b. Bottom avenue, simple filter as shown Gap > 1 and then another summary:
Group By OrderItem ...
Avg Gap to new output field AvgGap
Join the two strains back together on OrderItem and exclude Right_OrderItem from the output (uncheck its checkbox).
In Alteryx, this provides the output requested. There may be other ways but this is straight-forward without too much going on any step.

Related

Excel - getting a value based on the max value off another row in a Table

I'm looking for a solution for a problem I'm facing in Excel. This is my table simplified:
Every sale has an unique ID, but more people can have contributed to a sale. the column "name" and "share of sales(%)" show how many people have contributed and what their percentage was.
Sale_ID
Name
Share of sales(%)
1
Person A
100
2
Person B
100
3
Person A
30
3
Person C
70
Now I want to add a column to my table that shows the name of the person that has the highest share of sales percentage per Sales_ID. Like this:
Sale_ID
Name
Share of sales(%)
Highest sales
1
Person A
100
Person A
2
Person B
100
Person B
3
Person A
30
Person C
3
Person C
70
Person C
So when multiple people have contributed the new column shows only the one with the highest value.
I hope someone can help me, thanks in advance!
You can try this on cell D2:
=LET(maxSales, MAXIFS(C2:C5,A2:A5,A2:A5),
INDEX(B2:B5, XMATCH(A2:A5&maxSales,A2:A5&C2:C5)))
or just removing the LET since maxSales is used only one time:
=INDEX(B2:B5, XMATCH(A2:A5&MAXIFS(C2:C5,A2:A5,A2:A5),A2:A5&C2:C5))
On cell E2 I provided another solution via MAP/XLOOKUP:
=LET(maxSales, MAXIFS(C2:C5,A2:A5,A2:A5),
MAP(A2:A5, maxSales, LAMBDA(a,b, XLOOKUP(a&b, A2:A5&C2:C5, B2:B5))))
similarly without LET:
=MAP(A2:A5, MAXIFS(C2:C5,A2:A5,A2:A5),
LAMBDA(a,b, XLOOKUP(a&b, A2:A5&C2:C5, B2:B5)))
and here is the output:
Explanation
The trick here is to identify the max share of sales per each group and this can be done via MAXIFS(max_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...). The size and shape of the max_range and criteria_rangeN arguments must be the same.
MAXIFS(C2:C5,A2:A5,A2:A5)
it produces the following output:
maxSales
100
100
70
70
MAXIFS will provide an output of the same size as criteria1, so it returns for each row the corresponding maximum sales for each Sale_ID column value.
It is the array version equivalent to the following formula expanding it down:
MAXIFS($C$2:$C$5,$A$2:$A$5,A2)
INDEX/XMATCH Solution
Having the array with the maximum Shares of sales, we just need to identify the row position via XMATCH to return the corresponding B2:B5 cell via INDEX. We use concatenation (&) to consider more than one criteria to find as part of the XMATCH input arguments.
MAP/XLOOKUP Solution
We use MAP to find for each pair of values (a,b) per row, of the first two MAP input arguments where is the maximum value found for that group and returns the corresponding Name column value. In order to make a lookup based on an additional criteria we use concatenation (&) in XLOOKUP first two input arguments.

Grab minimum time in year

As an athlete I want to keep track of my progression in Excel.
I need a formula that looks for the fastest time ran in a given season. (The lowest value in E for a given year. For 2017, for example, this is 13.32, for 2018 12 and so on.
Can you help me further?
Instead of formula you can use PIVOT
Keep the Year in Report Filter and Time into Value. Then on value field setting select min as summarize value by.
So every you change the year in the Filter the min value will show up.
=AGGREGATE(15,6,E3:E6/(B3:B6=2017),1)
15 tell aggregate to sort the results in ascending order
6 tells aggregate to ignore any errors such as when you divide by 0
E3:E6 is your time range
B3:B6 is you Year as an integer.
B3:B6=2017 when true will be 1 and false will be 0 (provide it goes through a math operation like divide.
1 tells aggregate to return the 1st value in the sorted list of results

DAX Calculation with Datesbetween Ignores all Datefilters

I am starting with DAX.
I have a standard date table and a table with sales. When I try to show the running total with the below formula the month filter is ignored, as shown:
The formula is:
Prov YTD VJ 2:=CALCULATE(FIRMPROV[SumProv];
All(Kalender[Jahr]);
DATESBETWEEN(Kalender[Datum];
Min(START_YTD[start_ytd]);
MIN(END_YTD[end_ytd])))
A good way to calculate running totals is by using the FILTER and EARLIER functions, but a prerequisite to that is that you need to create a Month Number column (ie. Jan = 1, Feb = 2, Mar = 3, etc.)
Then, you can use the following DAX:
CALCULATE(SUM([SumProv]),ALL(FirmProv),FILTER(FirmProv,[Month Number]<=EARLIER([Month Number])))
EARLIER basically is DAX's way of interpreting the current row. You're telling DAX to sum ALL of the rows in the FirmProv table where the month number is less than or equal to the current row (AKA running total).
Here's the result (note the numbers aren't exactly like yours, I just quickly mocked it up to show the example):

Complex nested IFS in excel

So I have this output to track my tickets system that has the following columns:
1. create date
2. resolved date
3. location (A,B,C,D)
4. item (1,2,3,4)
How do I create a formula that could give me an output of average days open of an item in a week?
For example, week 32 of the year 2015, what is the average days open of item categorized '1' in location 'A'?
This shoudl be equal (total days open of all ticket '1')/(total tickets open of item '1') assuming I already know the total ticket opens.
And (resolved_date) – (create_date) if (last day of week) > (resolved_date), this indicates ticket is resolved within report week; = (last day of report week) – (create_date) if (last day of report week) < (resolved_date), this indicate ticket is resolved after report week; = (last day of report week) – (create_date) if resolved_date = null, this indicates ticket is not resolved by now.
I am thinking of a nested ifs formula like this IF( condition1, value_if_true1, IF( condition2, value_if_true2, value_if_false2 )) but not familiar with Excel enough to construct one.
Thanks!
Given what you've said, in my opinion it would be easier to break the data down into understandable steps. See the attached. I created some random data and a way to see by location and item the metric you describe at the beginning of any given work week. I'd recommend having Col A - D be the items you describe as 1-4 then make a columns adjascent E - H.
A = Create Date
B = Resolved Date
C = Location
D = Item
Formulas in each columns, row 2:
E: =IF($K$8>B2,"Closed",IF(A2<$K$8,"Open","Not Yet Open"))
F: =C2&D2
G: =IF(AND($F2=$K$5,$K$8>A2),1,0)
H: =IF(AND($F2=$K$5,$E2="Open"),$K$8-A2,0)
Make a menus tab. In column A put Locations in Cell A1, then all locations beneath it. Select the locations, including the header and hit Ctrl + Shift + F3. This will name the range of locations (Menus!A2:An), Locations. Do the same thing with Items in Column B. Now we can make some data validations. Now make a calendar tab. Put the first day of each WW in one column and the WW label in the next column. For example (12/28/2014 might be the first day of WW1). Add 7 the first date cell and drag it down. Drag the WW1 cell down to make it corresponding. Name the WW range 'WW'. Select the dates and the corresponding WW labels and name that 2-column range 'Calendar'
Head back to the page with your data. And do the following:
Location: (K3) Data Validation, List, Range =Locations
Item: (K4) Data Validation, List, Range =Items
Location + Item: (K5) =K3&K4
Work Week: (K7) Data Validation, List, Range =WW
First Day: (K8) =INDEX(Calendar,MATCH(K7,WW,0),1)
Total Days Open: (K10) =SUM(H:H)
Total Tickets: (K11) =SUM(G:G)
Avg Days Open: (K12) =K10/K11
Now you should be able to select the Location and item with drop downs and then a work week and get your metric.

Create an excel formula for "buy one, get the rest 50% off"

I need to create a formula in excel that will kind of do a "buy one item, get the rest at 50% off".
I need excel to pick the most expensive item and charge it at full value, then charge the rest at 50% of their value:
Item A=$30
Item B=$21
If on day one, item A was bought 2 times, and then item B was used once, I need excel to pick out the most expensive item of the day (which would be item A) and charge it at 100% of its value ($30) and then the for the second item A, charge it at 50% of its value ($15) and item B would also be at 50% of its value ($10.5). So the total charge for the day would be $55.50.
I have set up names for each item that correlates to its price. If I put =sum(itemA) in a cell in excel, then it comes up with 30.
I have it set up so that I can put in the number of each item that was bought and excel can multiple it for me =sum(itemA*2)-->60. I just need to figure out the 50% discount for all of the items bought in one day.
Please help, and let me know if there is anymore info that I need to share!!!!
ADDITIONAL:
I have added three items using the name function under "define name". Item A is equal to 30, item B equal to 21, item C equal to 15. So this is what I have set up for example, for day one:
Item Quantity Total price
item A 2 60 =sum(itemA*2)
item B 1 21 =sum (itemB*1)
item C 0 0 =sum (itemc*0)
total daily charges: 81 =sum(C2:C4)
total daily charges with discount: 55.5 (THIS IS WHERE I NEED THE FORMULA!)
ADDITIONAL:
Ok, so after working with this formula, I have another question:
I have two set of this data, and excel will pick the most expensive of the two sets and charge 100% and then charge the rest at 50%. However, I now need a way to separate out the charges for the two sets of data and get their total. So example:
Item A=30, item B=21, item C=15
Set one: item A used 2x, item B used 1x
Set two: item B used 1x, item C used 1x
Excel picks item A (as this is the highest in both sets) and charges it at 100% (30), then charges the rest of the items at 50% (43.5). The total that is charged is 73.5
Now I need excel to separate out the charges by set.
So set one, the charge is 55.5
set two, the charge is 18.
Please let me know if additional details are needed.
Assuming a layout as A:e below, three added columns might suit, with:
in F2: =MAX(IF(A:A=G2,C:C))
in G2: =IF(A2<>A3,A2,"")
in H2: =IF(G2=0,"",0.5*SUMIF(A:A,G2,E:E))+F2/2
each copied down to suit.
The first an array formula so entered with Ctrl+Shift+Enter.
The first identifies the daily maximum unit price (before discount).
The second to identify the daily summary.
The third for the calculations (same approach as #Ron Rosenfeld).
Depends on how you set things up, and you don't show that. It might be simpler to use an algorithm that computes 50% of everything, then add back 50% of the most expensive item. So if you have three columns: Items Prices Quantity, (where Prices = Price/Item) you could use a formula like:
=0.5*MAX(Prices)+SUMPRODUCT(Prices,Quantity)*0.5
If some entries in your "Quantity" column might be zero or blank, then use this formula instead:
=SUMPRODUCT(MAX(Prices*(Quantity>0))+SUMPRODUCT(Prices,Quantity))*0.5

Resources