Distinct Count Duplicate Value - excel

I need help for distinct count for duplicate value and output required as follows.
If Column A's value is 28 the result should be unique1(Column E) Else if Column A's value is 29 then the result should be Column F(Unique2)
Code Product Quantity Weight Unique1 Unique2
28 Apple 9 100 1 0
28 Orange 9 100 1 0
28 Apple 9 100 0 0
29 Apple 9 200 0 1
29 Apple 10 100 0 1
29 Apple 10 100 0 0
28 Orange 9 200 1 0
I tried Mr.tigeravatar code and it is working fine, but I don't know how to add an if ... else condition for checking and output in a different column.

For validation try this code: paste it in cell G2 or whatever preceding columns in row 2.
=IF(OR(AND(A2=28,E2=1,F2<>1),AND(A2=29,E2<>1,F2=1)),"Correct","Incorrect")

Related

Inner merge in python with tables having duplicate values in key column

I am struggling to replicate sas(another programming language) inner merge in python .
The python inner merge is not matching with sas inner merge when duplicate key values are coming .
Below is an example :
zw = pd.DataFrame({"ID":[1,0,0,1,0,0,1],
"Name":['Shivansh','Shivansh','Shivansh','Amar','Arpit','Ranjeet','Priyanka'],
"job_profile":['DataS','SWD','DataA','DataA','AndroidD','PythonD','fullstac'],
"salary":[22,15,10,9,16,18,22],
"city":['noida','bangalore','hyderabad','noida','pune','gurugram','bangalore'],
"ant":[10,15,15,10,16,17,18]})
zw1 = pd.DataFrame({"ID-":[1,0,0,1,0,0,1],
"Name":['Shivansh','Shivansh','Swati','Amar','Arpit','Ranjeet','Priyanka'],
"job_profile_":['DataS','SWD','DataA','DataA','AndroidD','PythonD','fullstac'],
"salary_":[2,15,10,9,16,18,22],
"city_":['noida','kochi','hyderabad','noida','pune','gurugram','bangalore'],
"ant_":[1,15,15,10,16,17,18]})
zw and sw1 are the input tables . Both the tables need to be inner merged on the key column Name .The issue is both columns are having duplicate values in Name column .
Python is generating all possible combinations with the duplicate rows .
Below is the expected output :
I tried normal inner merge and tried dropping duplicate row with ID and Name columns , but still not getting the desired output .
df1=pd.merge(zw,zw1,on=['Name'],how='inner')
df1.drop_duplicates(['Name','ID'])
Use df.combine_first + df.sort_values combination:
df = zw.combine_first(zw1).sort_values('Name')
print(df)
ID ID- Name ant ant_ city city_ job_profile \
3 1 1 Amar 10 10 noida noida DataA
4 0 0 Arpit 16 16 pune pune AndroidD
6 1 1 Priyanka 18 18 bangalore bangalore fullstac
5 0 0 Ranjeet 17 17 gurugram gurugram PythonD
0 1 1 Shivansh 10 1 noida noida DataS
1 0 0 Shivansh 15 15 bangalore kochi SWD
2 0 0 Shivansh 15 15 hyderabad hyderabad DataA
job_profile_ salary salary_
3 DataA 9 9
4 AndroidD 16 16
6 fullstac 22 22
5 PythonD 18 18
0 DataS 22 2
1 SWD 15 15
2 DataA 10 10

Finding a formula to compute partial sums for consecutive rows that satisfy a condition

How do I do this is excel. The example is provided below. If we don't sell any products on a specific day I would like to move those hours to the next date.
If you need to compute partial sums of Hours for all the consecutive rows between rows that satisfy the condition that the value Sold is greater than zero, you could do this with an auxiliary column
A B C D
---------------------------------
1 |Hours Sold Sums Solution
2 | 300 30 300 300
3 | 30 0 300 0
4 | 0 0 300 0
5 | 30 0 300 0
6 | 300 50 660 360
7 | 23 0 660 0
8 | 100 25 783 123
Here Sums is defined by a formula for C2
=IF(B2>0,SUM(A2:$A$2),C1)
You can automatically populate the cells below.
This formula puts in a cell a partial sum of Hours up to the current row if Sold is nonzero, otherwise copies the previous partial sum of hours. We need this to subtract this value on the next step.
When you have the column C filled, it is sufficient to put the following formula in D2 and populate the cells below
=IF(ROW(B2)>2,IF(B2>0,C2-C1,0),C2)
This formula handles correctly both D2 that does not have a preceding row with values and the remaining cells in column D.
In fact you could combine the two formulas together and avoid the need to have an auxiliary column. Put the following formula in C2 and spread it down to the rest of the cells in column C
=IF(ROW(B2)>2,IF(B2>0,SUM(A2:$A$2)-SUM(C1:$C$2),0),A2)
to get
A B C
---------------------------------
1 |Hours Sold Solution
2 | 300 30 300
3 | 30 0 0
4 | 0 0 0
5 | 30 0 0
6 | 300 50 360
7 | 23 0 0
8 | 100 25 123

Cumulative sum in excel with certain criteria

I have typed out an equation that I have dragged it down in a column in my excel table. I think I’m fairly close… and would love some feedback around this.
I want cumulative sum of the first cell $J$3 to the cell row it’s currently on (J53 for example). And I want cumulative sum of the particular cells that meet these conditions (ie… COUNTIF($B$3:B53,B53)*COUNTIF(AC53,1).
I know the Sumif() statement below isn’t correct… but this was as close as I could get!
=IF((COUNTIF($B$3:B53,B53)*COUNTIF(AC53,1)),(SUMIF($J$3:J53,J53)),0)
As shown in the table below
Projectid(B)
successornot(AC)
production(J)
result I want
1
1
20
20
1
1
40
60
1
1
10
70
2
0
20
0
2
0
400
0
3
1
20
20
4
0
1
0
5
0
24
0
6
0
50
0
7
1
10
10
7
1
40
50
7
1
20
70
Give a try on
=IF(B2=0,0,SUMIFS($C$2:$C2,$A$2:$A2,A2,$B$2:$B2,">0"))

excel:compare 2 columns and copy data on other columns

need help.. i trying to compare 2 columns and copy data in other columns..
Columns:
A B C D
1 3 10
2 4 20
3 1 30
4 2 40
5 0 50
i want to compare column A to B to find its duplicate and copy data from column C if column A has a duplicate at column B...
Result must be:
A B C D
1 3 10 0
2 4 20 40
3 6 30 10
4 2 40 20
5 0 50 0
thanks in advance...
An answer as I understand the question (assuming the change in col B is just a typo):
Input
A B C D
1 3 10
2 4 20
3 6 30
4 2 40
5 0 50
Output
A B C D
1 3 10 0
2 4 20 40
3 6 30 10
4 2 40 20
5 0 50 0
Formula in D2 (filled down): =IF(COUNTIF(B$2:B$6, $A2)>0, VLOOKUP($A2,$B$2:$C$6, 2, FALSE), 0).
COUNTIF(B$2:B$6, $A2) returns the number of times the value in A2 appears in the array B2:B6. If this value is greater than 0 (meaning that A2 is in B2:B6), the IF() function looks looks up A2 in col B and returns the value in the 2nd row (col C); if A2 is not in B2:B6, the formula returns 0.

Formula to find matching row value in multiple columns

I need a formula that would look in columns Jan, Feb & Mar to see if of the three months two months contained a 0, then in column 5 it would return the word win.
Store Jan Feb Mar Outcome
101 0
102 50 0
103 0 100
104 0 0 Win
105 0 0 Win
This should do the trick. (Placed in E2 and copied down)
=IF(COUNTIF(B2:D2,0)=2,"win","")
It counts how many zeroes are in columns B-D and if 2 then returns win

Resources