Power Query m Language Convert List to Single String Value with Separator - excel

{"Top 3 Max Sales Per Day", each Text.Combine(List.Transform(List.MaxN([Item Quantity Final], 3), each Number.ToText(_),",")), type number}
The Output Column is Still providing Error in each cell and I can't get the desired result to have the top 3 max values in one cell

Related

Find Rank of a Variable in my Dataframe within For Loop

I understand how to add a new column that shows the Rank of the number, but I am looking to change this to show the rank of a variable in that column...
list_of_values = [1,14,125,23,12]
df['price'] contains all 500 of my prices, and I'd like to see how 1 compares to these 500 or how 125 ranks (ties should reflect the minimum (e.g. if there are two values of price=1, the ranking should be 500/500 for both))

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.

getting another column is one column of data has maximum value in python?

I have a data frame
date object price
190403 a 1
190405 a 23
190506 b -4
190507 d 56
I want to get a date of a column having a maximum Price i.e 190507
expected output
190507
For scalar output, always one max date value use Series.idxmax with convert date to index by DataFrame.set_index:
df.set_index('date')['price'].idxmax()
If want all max values in Series use boolean indexing and compare all values by max, DataFrame.loc is fir also filtering date column:
df.loc[df['price'].eq(df['price'].max()), 'date']
You can subset the df so that you only have the row where the price column is at its maximum, and then choose the date column:
df[df.price==df.price.max()].date

Spotfire over function - previous date with multiple categories

I'd like to calculate a value difference between two rows that is classified by Type and ID and is sorted by a date column. See example data table. Note that column "Calculated" shows the current results, while column "Expected" shows the results I would like to achieve.
ID Type Date ValueA ValueB ValueC Calculated Expected
1 A 8/15/2017 38.11
1 A 8/15/2017 78.10 39.99
1 A 8/22/2017 110.24 32.14
1 B 8/22/2017 20
1 B 9/16/2017 10
1 A 9/16/2017 101.13 -9.11
2 C 8/17/2012 90
2 A 8/18/2012 863.25
2 B 8/18/2012 15
2 A 8/19/2012 952.35 89.1 89.1
2 B 8/19/2012 20
I tried the following custom expression, but it seems to calculate a difference value only for cases where there is a consecutive date for a given ID.
Case
when [Type]="A" then [Value] - Max([Value]) over (Intersect([ID],Previous([Date])))
else NULL
The expression is an attempt to filter to Type "A" for the OVER statement, such that the previous date is the previous date only for values categorized as Type "A". However, it seems to consider the previous date as NULL if is not a consecutive date (i.e. prior day). See "Calculated" in table above for results from this expression.
I also tried to add Type to the Intersect statement, e.g. Intersect([ID],[Type], Previous([Date]), but I get a similar result.
does
[value] - max[value] over (intersect([Type],[ID],previous([Date])))
give you the calculated column you want
Edit:
I was able to almost match your expected column using this formula (previousperiod instead of just previous), but the first two rows are the same date so it is not an exact match.
formula

Return value in cell based on other cells values combination in excel

I have a table in Excel that has the following columns:
My table
dm: Can be 0 or 1
gdr: Can be 0 or 1
smk: Can be 0 or 1
agemin: min age number
agemax: max age number
sbpmin: min sbp number
sbpmax: max sbp number
chlmin: min chl number
chlmax: max chl number
The table is big with all possible combinations.
What i need is a way to find the value in result based on the input of:
dm, gd, smk, age, sbp and chl. As i mention the first 3 can be a 0 or a 1 but the other 3 is a number that must be contain in the range given by the columns min and max.
Has anyone have a clue on how can i solve this?
Thanks,
Using the provided table and assuming the parameters for a lookup are in column M (as shown in the below picture), then the formula in cell M9 and copied right to get the result is:
=IFERROR(INDEX($J$2:$J$4,MATCH(1,INDEX((M2=$A$2:$A$4)*(M3=$B$2:$B$4)*(M4=$C$2:$C$4)*(M5>=$D$2:$D$4)*(M5<=$E$2:$E$4)*(M6>=$F$2:$F$4)*(M6<=$G$2:$G$4)*(M7>=$H$2:$H$4)*(M7<=$I$2:$I$4),),0)),"No matches found")

Resources