INDEX returns wrong value and no value - excel

I'm trying to find matching values and sort them in a column.
Column A contains Names and Column B Training Done by person in Column A.
An example of my data can be seen here:
Having that data, I want to get a separate table with two Columns(Name and training). In Column C, I want the names and in Column D I want the training done by who is in Column C.
=IFERROR(INDEX($B$2:$B$7,SMALL(IF($C2=$A$2:$A$7,ROW($A$2:$A$7)-1,""),ROWS($D$1:D1))),"No training done")
I've tried using the above formula, but it seems to only work for the first entry in the table. I can't figure out what i should change.
This is what I get
It shows "No training done" to people who have had training and there's a "0" where it should be "No training done".
This is my expected result:
L.E : Anna did Excel. A mistake on my part in the above picture. Also, I'm only interested in the Training Column, as I already got the hang of the formula to order the names.
Thank you.

Enter this formula in D2:D7:
= IFERROR( INDEX( $A$2:$A$7,
AGGREGATE( 15, 6,
MATCH( $A$2:$A$7, $A$2:$A$7, 0 ),
ROWS( B2:B$2 ) ) ), "" )
Then enter this formula in E2:E7
= IFERROR( TRIM( SUBSTITUTE( REPT( " ", 3 ) & INDEX( $B$2:$B$7,
AGGREGATE( 15, 6,
ROW(E:E) / ( ( $A$2:$A$7 = D2 ) * 1 ),
COUNTIF( D$2:D2, D2) ) ) & REPT( " ", 3 ), REPT( " ", 6 ), "No Training done" ) ), "" )

=INDEX(Training,AGGREGATE(15,6,1/(C2=Names)*ROW(Names),COUNTIF($C$2:$C2,$C2))-1)
In this instance, I used a custom format for the result of: ;;"No Training Done";#
but, if you don't mind a longer formula, you can use an IF function to return the No Training Done statement in the event the formula returns nothing.
=IF(INDEX(Training,AGGREGATE(15,6,1/(C2=Names)*ROW(Names),COUNTIF($C$2:$C2,$C2))-1)=0,"No Training Done",INDEX(Training,AGGREGATE(15,6,1/(C2=Names)*ROW(Names),COUNTIF($C$2:$C2,$C2))-1))
Also, you can use whole-column references if you want. If you do that, remove the -1 as you won't have to adjust for the header row.
If you wanted to use Power Query aka Get&Transform, it would just be a matter of replacing the null with No Training Done and then sorting the result per your desired order. That can all be done from the PQ Editor GUI, and below is the M-code
M-Code
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Names", type text}, {"Training", type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type",null,"No Training Done",Replacer.ReplaceValue,{"Training"}),
#"Sorted Rows" = Table.Sort(#"Replaced Value",{{"Names", Order.Ascending}})
in
#"Sorted Rows"

The easiest way will be:
1) Copy and paste your information to columns C:D
2) On cell A:2 place =COUNTIF($C$2:C2,C2) and drag it to your row range.
3) On cell B:2 place =C2&A2 and drag it to your row range.
4) On cell E:2 place =B2 and drag it to your row range.
5) On cell F:2 place =IF(VLOOKUP(E2,$B$2:$D$7,3,FALSE)="","",VLOOKUP(E2,$B$2:$D$7,3,FALSE))
6) Hide columns A:B
Hope it helps

Related

Find most common combinations and how many times they occur

In the example below I want to search each unique order and then the items in that order. From that I would like to extract the most common items that are ordered together and how many times they occur together. This is just a sample. I am doing this with a file with 20,000 rows.
Sorry, I haven't earned enough points to embed the photo. It's in the link below.
Screenshot of the example
Use this formula to get the occurrences with one formula one cell.
=ArrayFormula({ "Occurrences",$B$1:$F$1;
QUERY({COUNTIF(
B2:B&C2:C&D2:D&E2:E&F2:F,
"="&QUERY({ARRAY_CONSTRAIN(UNIQUE($B$2:$F),ROWS(UNIQUE($B$2:$F))-1,COLUMNS(UNIQUE($B$2:$F)))}, " Select Col1 ")&
QUERY({ARRAY_CONSTRAIN(UNIQUE($B$2:$F),ROWS(UNIQUE($B$2:$F))-1,COLUMNS(UNIQUE($B$2:$F)))}, " Select Col2 ")&
QUERY({ARRAY_CONSTRAIN(UNIQUE($B$2:$F),ROWS(UNIQUE($B$2:$F))-1,COLUMNS(UNIQUE($B$2:$F)))}, " Select Col3 ")&
QUERY({ARRAY_CONSTRAIN(UNIQUE($B$2:$F),ROWS(UNIQUE($B$2:$F))-1,COLUMNS(UNIQUE($B$2:$F)))}, " Select Col4 ")&
QUERY({ARRAY_CONSTRAIN(UNIQUE($B$2:$F),ROWS(UNIQUE($B$2:$F))-1,COLUMNS(UNIQUE($B$2:$F)))}, " Select Col5 "))
}, "Select Col1 where Col1 <> 0 "),
ARRAY_CONSTRAIN(UNIQUE($B$2:$F),ROWS(UNIQUE($B$2:$F))-1,COLUMNS(UNIQUE($B$2:$F))) })
Option 02
=ArrayFormula({ "Occurrences",$B$1:$F$1;
QUERY({ARRAY_CONSTRAIN(COUNTIF(
FLATTEN(QUERY(TRANSPOSE(B2:F), "",9^9 )),
"="&FLATTEN(QUERY(TRANSPOSE(ARRAY_CONSTRAIN(UNIQUE($B$2:$F),ROWS(UNIQUE($B$2:$F))-1,COLUMNS(UNIQUE($B$2:$F)))), "",9^9 ))),
COUNTA(FLATTEN(QUERY(TRANSPOSE(ARRAY_CONSTRAIN(UNIQUE($B$2:$F),ROWS(UNIQUE($B$2:$F))-1,COLUMNS(UNIQUE($B$2:$F)))), "",9^9 ))),1)
}, "Select Col1 where Col1 <> 0 "),
ARRAY_CONSTRAIN(UNIQUE($B$2:$F),ROWS(UNIQUE($B$2:$F))-1,COLUMNS(UNIQUE($B$2:$F))) })
I hope that helped ^_^
Alternate Solution (with Helper Columns):
Though the other solution posted works I've figured this will not count it in the same combination if the items are interchanged. For example:
This will be counted as 1 for each even they are the same combination.
So here's another solution if you don't mind using helper columns:
1.) Use this formula in 1 column to combine all items in the order:
=TEXTJOIN(", ", TRUE, SORT(TRANSPOSE(E2:I2), 1, TRUE))
Drag down to column.
This uses SORT() function to first sort the items alphabetically before using TEXTJOIN() function to concatenate the items into one cell. This is so that it will not matter even if the items are interchanged.
2.) Use the UNIQUE() function to remove the duplicates.
=UNIQUE(K2:K15)
3.) Use the COUNTIF() to count the number of occurences. Then the IF() to only apply it for rows that are not blank. Then ArrayFormula() so there's no need to drag down the formula to the column you just need to input in the first row.
=ARRAYFORMULA(IF(L2:L<>"",COUNTIF(K2:K,L2:L),""))
Final Result:
Limitation:
This can't count as same combination if the total order is not the same. For example:
They will be counted as 1 each.
References:
Concatenate and Alphabetize
If Not Empty
try this and notice the blue cells:
=ARRAYFORMULA(TRIM(SPLIT(FLATTEN(QUERY(TRANSPOSE(QUERY(QUERY(QUERY(TRIM(SPLIT(FLATTEN(
QUERY(QUERY(IFERROR(SPLIT(FLATTEN(IF(E2:I="",,ROW(E2:I)&"♠♦"&PROPER(E2:I)&"♥")), "♦")),
"select max(Col2) where Col1 <> '♠' group by Col2 pivot Col1"),,9^9)), "♠")),
"select count(Col2),Col2 where Col2 is not null group by Col2 order by count(Col2) desc"),
"select Col1,'♥',Col2"), "offset 1", )),,9^9)), "♥")))
Solution with PowerQuery
You can add as many Item-Colums you want (Columnname must have the word "Item" in it -> "Item 6", "Item 7", "Last Item", "My Item", "Special Item" ...)
You do not have to adjust any range in a cell formula
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Inserted Merged Column" = Table.AddColumn(
Source,
"Combination",
each Text.Combine(
List.Sort(
List.Transform(
List.Select(
Table.ColumnNames(Source),
each Text.Contains(_,"Item")
)
, (col)=> Record.Field(_, col)
)
),
"; "), type text
),
#"Grouped Rows" = Table.Group(#"Inserted Merged Column", {"Combination"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
#"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Count", Order.Descending}})
in
#"Sorted Rows"
It's a tough one with multiple combinations and order sequence matters. A not so complete answer for only the first two items would be:
Formulas Layout
In Cell K2 =E2&" "&F2
In Cell M2 =COUNTIF($E:$I,L2)
In Cell O2 =COUNTIFS($K:$K,$L2&" "&O$1)
That would only add up the first two items in each order in a matrix style layout and I added conditional formatting for viewing higher numbers in the matrix.

Add Same Text To Multiple Cells In One Column using Excel formula

I have an excel spreadsheet with two columns with example data
Name
Quantity
Dell v1
12
HP v1
4
I've created a new sheet, and wanted to know which formula allows me to add the text value 'Dell v1' to 12 cells in a single column? I understand I can copy & paste, drag down etc....
Name
Dell v1
Dell v1
Dell v1
Dell v1
Dell v1
Dell v1
Dell v1
Dell v1
Dell v1
Dell v1
Unless I have misunderstood the objective, with Office 365, you can do:
=LET( series, A2:A3,
by, B2:B3,
elements, SUM( by ), eSeq, SEQUENCE( elements,,0 ),
bySeq, SEQUENCE( ROWS( by ) ),
byPos, MMULT( --(bySeq >= TRANSPOSE( bySeq )), by ),
INDEX( series, IFERROR(MATCH( eSeq, byPos, 1 )+1,1), 0 ) )
where the Name is in series and the Quantities are in by.
LAMBDA Helper
I just realized it could be shorter with a LAMBDA helper:
=LET( series, A2:A3,
by, B2:B3,
eSeq, SEQUENCE( SUM( by ),,0 ),
byPos, SCAN(0,by,LAMBDA(a,b,a+b)),
INDEX( series, IFERROR(MATCH( eSeq, byPos, 1 )+1,1), 0 ) )
As per my comment, this seems to be a nice task for PowerQuery. Load your data from the table, and assuming the the name of the table to be 'table1', you can change the M-code in the advanced editor to the following:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
Typed = Table.TransformColumnTypes(Source,{{"Name", type text}, {"Quantity", Int64.Type}}),
Repeated = Table.TransformColumns(Typed, {"Quantity", each List.Numbers(_,_,0), type list}),
Expanded = Table.ExpandListColumn(Repeated, "Quantity"),
Finished = Table.RemoveColumns(Expanded,{"Quantity"})
in
Finished
Then close PowerQuery and it will load the data back into Excel.
Make it relatively easy by using helper column,
• In A3 put the number 1
• In A4 put formula =A3+C3 and copy down
• In E3 put formula
=VLOOKUP(ROW(A1),$A$3:$B$5,2,TRUE)
and drag down as far as it needs to go.

How To Filter Both Rows And Columns On Multiple Criteria In Excel

As an example, see the below data.
I can FILTER by row with:
=FILTER($A$1:$E$9,
((ISNUMBER(SEARCH("b",$A$1:$A$9)))+
(IFERROR($A$1:$A$9="List",FALSE))+
(IFERROR($A$1:$A$9="",FALSE))))
I can also FILTER by column with:
=FILTER($A$1:$E$9, $A$1:$E$1="1600m")
But when I try to filter by both simultaneously, I get #VALUE!.
Below are my two tries:
1)
=FILTER($A$1:$E$9,
((ISNUMBER(SEARCH("b",$A$1:$A$9)))+
(IFERROR($A$1:$A$9="List",FALSE))+
(IFERROR($A$1:$A$9="",FALSE)))*
($A$1:$E$1="1600m"))
=FILTER($A$1:$E$9,
((ISNUMBER(SEARCH("b",$A$1:$A$9)))+
(IFERROR($A$1:$A$9="List",FALSE))+
(IFERROR($A$1:$A$9="",FALSE))*
($A$1:$E$1="1600m")))
I have also thought about utilizing LET to first filter by column, and then filter the already filtered array by row, but I don't believe I can reference specific rows in the function.
Any ideas?
Perhaps you can index your row filter:
=INDEX(
FILTER(A1:E9,(ISNUMBER(SEARCH("b",$A$1:$A$9))+
(IFERROR($A$1:$A$9="List",FALSE))+
(IFERROR($A$1:$A$9="",FALSE)))),
, MATCH( "1600m", $A$1:$E$1,0) )
If you don't want the header:
=INDEX(
FILTER(A1:E9, ISNUMBER(SEARCH("b",$A$1:$A$9) +
IFERROR($A$1:$A$9="List",FALSE) +
IFERROR($A$1:$A$9="",FALSE))),
, MATCH( "1600m", $A$1:$E$1,0) )
As P.b. proposed, nested FILTER can be done to deliver the result with header:
=FILTER( FILTER( $A$1:$E$9, $A$1:$E$1="1600m"),
(ISNUMBER(SEARCH("b",$A$1:$A$9)) +
(IFERROR($A$1:$A$9="List",FALSE)) +
(IFERROR($A$1:$A$9="",FALSE))) )
If the output needs to be as shown in H1:E5 of your image, this (over-engineered for illustration) LET delivers it, just in case:
=LET(t, $A$1:$E$9, list, $A$1:$A$9, horse, "b", raceDist, "1600m",
raceHeader, INDEX(t, 1, ),
rf, FILTER(t, ISNUMBER(SEARCH(horse,list)) +
IFERROR(list="List",FALSE) +
IFERROR(list="",FALSE) ),
idxR, SEQUENCE(ROWS(rf)),
rf_rowLabels, INDEX(rf,idxR,{1,2}),
target, INDEX( rf, , MATCH( raceDist, raceHeader, 0 ) ),
IFERROR( INDEX(SUBSTITUTE(INDEX(rf,SEQUENCE(ROWS(rf)),{1,2}),0,""), idxR,{1,2,3}),
target ) )
Edited out the first SUBSTITUTE - I forgot that it was still there. Thanks P.b.
=FILTER( FILTER($A$1:$E$9,($A$1:$E$1="1600m")+($A$1:$E$1="Event:")+($A$1:$E$1="")), ((ISNUMBER(SEARCH("b",$A$1:$A$9)))+ (IFERROR($A$1:$A$9="List",FALSE))+ (IFERROR($A$1:$A$9="",FALSE))))
First the conditions for the column headers, followed by the conditions for your rows.
PS Empty cells are displayed as 0

Excel Power Pivot - Nested IF OR Formula error

I have been trying to use the formula mentioned below which is not working and showing an error message stating "Power pivot expression that yield variant data-type cannot be used to define calculated columns"
IF (
OR ( Table2[TeamStatus] = "Lost", Table2[TeamStatus] = "Won't proceed" ),
"0",
IF (
OR ( Table2[TeamStatus] = "Next level", Table2[TeamStatus] = "Disqualified" ),
"0",
IF (
AND ( YEAR( Table2[Match Date] ) = YEAR( TODAY() ), [TeamStatus] <> "Won" ),
[Spent Amount],
0
)
)
)
Data types of the columns
1) [TeamStatus] = Text
2) [Match Date] = Date
3) [Spent amount] = Number
The purpose of this formula is to exclude the following rows from [TeamStatus] column (i.e. in the [TeamStatus] column is having "Lost", "Won't proceed", "Next Level", "Disqualified" texts) then the output should be zero and then calculate the spent amount for all other categories in [TeamStatus] column and another condition (i.e. if the year is current year) is met.
I have been trying from past 1 day to make this formula work and no luck. I also tried using FORMAT() function and still it is not working.
Can someone please help me?
The error is saying that your formula should either return a number or text but not sometimes a number and sometimes text.
Notice that your formula sometimes returns "0" and sometimes returns 0.
Either change the first two zeros to be numbers instead of text or else change the last zero to text and use FORMAT on [Spent Amount] to convert it to text.
As a side note, can't your formula be simplified to just?
IF (
AND ( YEAR ( Table2[Match Date] ) = YEAR ( TODAY () ), [TeamStatus] = "Won" ),
[Spent Amount],
0
)

Searching for DAX formula - equivalent to Excel SUMIF

I am searching for a DAX formula.
Specifically:
If SOLD (1st column) = count volume (second column), if not SOLD = 0
I need to reflect the volume of SOLD in a new column. UNSOLD Volumes should be 0.
I attach the reduced data set.
If I understand, you want to only perform aggregation when the SOLD_UNSOLD column is equal to "SOLD", otherwise return 0? If so, the following formula will do this, you'll just need to update the column names accordingly. The outer IF prevents problems resulting from further evaluation (i.e. grand totals) and it's necessary to wrap the column in the VALUES function as this will turn the column into a table of the unique values of it.
'YourTable'[CountOfSold] =
IF (
COUNTROWS ( VALUES ( YourTable[SOLD_UNSOLD] ) ) = 1,
IF (
VALUES ( YourTable[SOLD_UNSOLD] ) = "SOLD",
COUNT ( YourTable[ColumnToAggregate] ),
0
),
0
)
The Excel SUMIF is closest to the DAX SUMX.
I'm not positive I'm understanding what you are asking for, but I think you'd want something like this:
SOLD_VOLUME = SUMX(Table1,
IF(Table1[SOLD_UNSOLD] = "SOLD",
Table1[DAILY_VOLUME],
0
)
)
You could also do this with a filter:
SOLD_VOLUME = SUMX(
FILTER(
Table1,
Table1[SOLD_UNSOLD] = "SOLD"
),
Table1[DAILY_VOLUME]
)

Resources