I have one column that contains text such as,
column1
3
4
5
6
7
8
9.2
10
11
txt1
txt2
I want to create a new column2 that gives me the following output.
column1 column2
3 3-6
4 3-6
5 3-6
6 3-6
7 7-10
8 7-10
9.2 7-10
10 7-10
11 11
txt1 txt1
txt2 txt2
I have tried with the following Dax function but i dont get it to work as it only returns "value if false". My format on Column1 is text.
column2 = IF(CONTAINS(Table1;Table1[column1];"3";Table1[Column1];"4");"3-8";"9.5-10").........
I have tried with the FIND function aswell without luck.
Someone have any tips? If someone nows how to do this in Excel perhaps it could be figured out that way?:D
/D
I'm not sure exactly what your logic for bucketing values is, but you should be able to write something along these lines:
Column2 = SWITCH(TRUE(),
ISERROR(VALUE(Table1[Column1])), Table1[Column1],
VALUE(Table1[Column1]) >= 3 && VALUE(Table1[Column1]) <= 6, "3-6",
VALUE(Table1[Column1]) >= 7 && VALUE(Table1[Column1]) <= 10, "7-10",
Table1[Column1])
This SWITCH function will return the first thing that evaluates to true, otherwise, it returns the last argument. The first pair checks if the value can be converted to a number and if not returns the original value. The next two pairs check if the number is in certain ranges and returns specified strings for those ranges.
Here's a link that explains the SWITCH(TRUE()...) construction in more detail:
https://powerpivotpro.com/2015/03/the-diabolical-genius-of-switch-true/
Related
I would like to use a concatenate formula in Excel that also includes the superscript number 2 (squared symbol), but this does not work with the following input. The formula is roughly like this:
=CONCATENATE("13";"²")
i want to get an output like this:
13²
I tried using superscript functions on the font
but it didn't work when the text is inside the concatenation.
I have to use concatenate because I want to automate.
Is it possible to do with Excel 2019 there? or is it possible but would require VBA?
Try
=CONCATENATE("13";CHAR(178))
Using superscript digits via udf
Superscript digits ranging from 0 to 9 have code values in different unicode sections. Thus using the following user defined function (udf) allows you to get each digit from 0 to 9 as superscript character without the need to detect & memorize each code value again and again.
The hexadecimal and decimal codes are commented in the function below:
Function sup(ByVal digit As Long)
Dim n As Long
Select Case digit
Case 0: n = &H2070 ' dec 8304
Case 1: n = &HB9 ' dec 185
Case 2: n = &HB2 ' dec 178
Case 3: n = &HB3 ' dec 179
Case Else ' <super> 4 .. 9
n = &H2074 + digit - 4 ' dec 8308 .. 8313
End Select
sup = ChrW(n)
End Function
Some examples (~~> output x³)
="x" & sup(3)
=CONCAT("x",sup(3))
=CONCAT("x",sup(Sheet1!A2)) ' assuming a digit value of 3 in Sheet1!A2
or within VBA assignments like e.g.
Sub ExampleCall()
Dim i As Long
For i = 0 To 9
Sheet1.Range("A2").Offset(i).Value = "x" & sup(i)
Next
End Sub
I also found a way to make this work without using concatenate, it just requires making a table to map to superscript numbers.
Step 1: Characters Table
Somewhere else, build a simple table with a map from "Digit" numbers to "Superscript" numbers.
In the first column, "Digit", just type something like:
-9
-8
-7
-6
-5
-4
-3
-2
-1
0
1
2
3
4
5
6
7
8
9
In the second column, "Superscript", go to Excel Ribbon Insert > Symbol. In the tab "Symbol", change the comboboxes "Font" to "(normal text)" and "Subset" to "Superscripts and Subscripts". Insert now each character in its corresponding cell be sure to use "Superscript Minus" for negative numbers. Superscripts 1, 2 and 3 are located in the subset "Latin-1 Supplement".
-9 ⁻⁹
-8 ⁻⁸
-7 ⁻⁷
-6 ⁻⁶
-5 ⁻⁵
-4 ⁻⁴
-3 ⁻³
-2 ⁻²
-1 ⁻¹
0 ⁰
1 ¹
2 ²
3 ³
4 ⁴
5 ⁵
6 ⁶
7 ⁷
8 ⁸
9 ⁹
And so on. Please notice that these are not "formatted" numbers, but special symbols with no numeric value.
Step 2: Vlook Function
Put the digit you want displayed normally in a column, set up like it is in 'A1' below, i.e.:
Cell A1: 13
Then, put the number you want to be displayed in superscript format, i.e.:
Cell B1: 3
Then, use this function to create the final output.
Cell C1: =A1&VLOOKUP(B1,Sheet2!$A$1:$B$20,2,FALSE)
First time asking in the forum.
I have a problem.
I have to loop thru a vertical list like this.
1
2
3
4
5
6
7
8
9
10
11
Each separated by enter key, not by space. And then reorganize each item/number descending.
For the descending organization i already know it can be sorted or sorted reverse. But for all I have tried I cannot loop thru all the items in the vertical list.
It only reads 1 and ends the cycle which I understand it is only reading the first list but I just do not know how to loop thru vertical lists be it 1 single value or a matrix.
This is my code
from pip._vendor.distlib.compat import raw_input
numbers = raw_input()
line = []
for row in numbers:
line.append(row)
print(line)
line.sort(reverse=True)
for value in line:
print(value)
input:
1
2
3
4
5
6
7
8
9
10
11
Once again each separated by enter key, not by space
output:
['1']
Thanks in advance for your support.
Im new in pandas so would like to ask some help according to excel file.
Here I have some sheet with column 1:
Index Column1
1 PF7293
2 NodeB Name=SN5208, LogicRNCID=106
3 KL5083
4 Label=DL7765A3U-2, CellID=28643, LogicRNCID=201
and I wanna create another column2 that should have some word from column1 and look like that:
Index Column2
1 PF7293
2 SN5208
3 KL5083
4 DL7765
in excel we used MID. I would like to do the same using pandas. Thank you!
Question 2
New sheet looks like that:
Column1 Column2
KL7110 BTS works
KS5007 BSS works
KL5066 Planned works
KL5147 Planned works
KL5066 Unplanned work
KL5077 Power work
KL5077 Power work
AN9045 MW work
I wanna delete same value from Column 2 for one value in column1.
For example here is 2 KL5077 in column1 with same value in column2 I would Like to delete one of them.
And second problem here is 2 KL5066 in Column1 with different value in Column2 and in this case I would like to put values in Column2 together like "Planned work/Unplanned work". Hope I ve explained well))
You could try Series.str.extract:
df['Column2'] = df['Column1'].str.extract(r'([A-Z]{2}\d{4})')
Where the regex pattern here can be though of as "2 uppercase letters" followed by "4 digits"
[out]
Index Column1 Column2
0 1 PF7293 PF7293
1 2 NodeB Name=SN5208, LogicRNCID=106 SN5208
2 3 KL5083 KL5083
3 4 Label=DL7765A3U-2, CellID=28643, LogicRNCID=201 DL7765
Update
For the 2nd problem:
1) To drop duplicate rows use:
df.drop_duplicates(subset=['Column1', 'Column2'], inplace=True)
2) To join multiple 'Column2' values use:
df_new = df.groupby('Column1')['Column2'].apply('/'.join).reset_index()
[out]
Column1 Column2
0 AN9045 MW work
1 KL5066 Planned works/Unplanned work
2 KL5077 Power work
3 KL5147 Planned works
4 KL7110 BTS works
5 KS5007 BSS works
I have an excel worksheet with something like below. The desired output are as shown in column G and the last row, which concatenates all the values in columns/rows and gives the value of the resultant expression.
It's actually some kind of a puzzle where the aim is to replace some numbers with operators such that the values in G matches with a specified value. I am replicating the same in excel from a paper version.
A B C D E F G
3 3 33
4 1 + 2 43
4 0 + 5 6 4 604
7 3 2 / 1 2 61
3 7 2 7 3727
3 0 30
47 4033 304 0.4 2617 42
I have tried the following formula:
="="&A2&B2&C2&D2&E2&F2
However it gives the result in text format instead of 43, which I expected:
=41+2
Is there any way to give the final output as 43.
I developed (recorded and modified) a macro which simply copies the above result, paste it as values in Column H and then run 'text to columns' on the column H which gives me the desired output exactly as expected. However, I still can't figure out how to do the same with the row.
Is there any way to achieve the above with a formula only?
I want to avoid using macros as the undo functionality is lost but suggestions are welcome.
You could create a UDF that uses Application.Evaluate to evaluate the text string into a value. Then your formula would just need =Eval(A2&B2&C2&D2&E2&F2)
Function Eval(txt As String)
Eval = Application.Evaluate(txt)
End Function
I'm looking for a way to find the first specific value above a certain cell.
Using the example below, in the result column every time I hit a A in COL2, I need to substract the value in COL1 to the first A value above.
The trouble seems finding a way to keep the range dynamic...
I thought of =IF(B5="A";A5-INDIRECT("A"&MATCH("A";B:B;0));"")
But of course that only works for the first one as Match will always pick up the first one.
Any ideas? Thanks!
Example :
COL1 COL2 Result
1 A
2 0
3 0
4 A 4 - 1 = 3
5 0
6 A 6 - 4 = 2
7 0
8 0
9 0
10 A 10 - 6 = 4
Try this:
=IF(AND(ROW(B2)<>2,B2="A"),A2-INDEX($A$1:$A1,AGGREGATE(14,6,ROW($1:1)/($B$1:$B1="A"),1)),"")
The AGGREGATE() Function was introduced in 2010.
In D2 enter =IF(B2="A",A2-INDIRECT("A"&MATCH("A"&(E2-1),F:F,0)),"")
In E2 enter =IF(B2="a",COUNTIFS($B$2:B2,"a"),"")
In F2 enter =B2&E2
Copy formulas from D, E and F down all your rows
Column D is the result you're looking for