I am using a table from an excel file which has a TEXT column "Service Code".
When I upload the data into Power BI, it automatically changes the field type to number and removes leading zeros. For Example, "000230" becomes "230", and "010000" becomes "10000". I created a custom column and used = Number.ToText([#"Service Code"],"000000). This worked as all values in the column are 6 digits long, however, a few of them have a letter at the end which is causing error. For example,10014A or 10017Z. Is there a way to do this without causing error?
Service Code
Custom
Desired output
230
000230
000230
10000
010000
010000
10014A
Error
10014A
10017Z
Error
10017Z
I used the "Custom Column from Examples" feature in PowerQuery and typed in the first two required values.
It created this formula:
Text.PadStart(Text.From([orig], "en-US"), 6, "0")
Related
Using SSRS
All the other questions are how to force the number to show as a number instead of text when exporting to Excel
Meanwhile I want to force the number to show as a text so that Excel does not turn number 6158.30 to 6158.285 which is causing me round up issues.
My SQL uses cast to 2 decimal places CAST(ROUND(Net, 2) AS decimal(18,2)), in Excel it shows as 6158.30 but when you click on the cell its showing 6158.285.
I have tried concatenating ' + value but it exports the data as 'value and NOT force the cell to show as a text data.
I don't think it makes sense to try to turn the number into text, when all you are trying to do is to prevent the number displaying with more than 2 decimal places in Excel.
From the behavior you have described, it sounds like that for the textbox, you are currently using an SSRS expression like:
=Fields!Net.Value * 148.5
and using the Format property of the textbox to display to 2 decimal places.
Instead, for the SSRS expression, try:
=Round(Fields!Net.Value * 148.5, 2)
No need to set the textbox's Format property (unless you want commas etc).
Then that textbox column should stay as a number to 2 decimal places, when the report is generated to Excel, and the cell selected.
I am having an issue summing a column of dollar amounts in a DataTable with VB. I have tried two different ways resulting in two different errors which I am not sure how to resolve. Before I go into the two ways I have tried to solve the problem here is the setup:
I am importing a tab delimited file into a DataTable. The headers are automatically populated with data from the first row in the file.
The DataGridView that displays the Datatable is called DGV_detail.
The column in DGV_detail I am trying to sum occurs at column 3 and is called 'Value-to-date'. This column is full of dollar amount values similar to: $10.00 With the dollar sign and everything.
I am also declaring a view variables and doing some calculations when a button is clicked.
Here is my first approach:
For i As Integer = 0 To DGV_detail.Rows.Count() - 1 Step +1
interestPaidToAccounts = interestPaidToAccounts + DGV_detail.Rows(i).Cells(3).Value
Next
When I try this approach I get the following error:
An unhandled exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll
Conversion from string "" to type 'Double' is not valid.
The other methods I was trying to use to solve the problem were (For reference: In these examples I created a variable local to the button_click function that assigned the BGV_detail.DataSource to equal dataTable1):
Dim sumObject = dataTable1.Compute("Sum(Convert(Value-to-date, 'System.Decimal'))", "[Value-to-date] IS NOT NULL")
and
Dim sumObject As Decimal = dataTable1.Compute("Sum(Value-to-date)", "")
Which both produced the following error:
Expecting a single column argument with possible 'Child' qualifier.
I am pretty lost at this point so whatever the community thinks the best method to resolves these problems is, I am open to.
I can provide additional information if needed! :)
Thanks in advance for your help!
The dollar sign is the issue, use mid to remove it and val to convert to number:
val(mid(DGV_detail.Rows(i).Cells(3).Value, 2,DGV_detail.Rows(i).Cells(3).Value.length -1))
Untested, but should get you started ... there are any number of ways to remove the $.
It looks like google sheets is making the same mistake as Excel, by "thinking ahead" and converting the value "1.1.1" to 2001.01.01 when doing sheet.appendRow. I have tried to set the number format of the column in charge to "#" (which should be plain text) before inserting rows - but looks ineffective. On the other hand doing the same after inserts is also ineffective, as the content is already "date".
Adding ' before is working, but it is not what I need.
Is there any way to give a default format or to disable such automatic conversion (from google script)?
I have a cell in which a form deposits a variable number of values seperated by a comma such as: " 1, 2, 4, 6 " etc - when there are only three answers, Google "helps" me by converting the value into a date object. But it's supposed to be a list of choices...
It's not pretty, but I've managed a workaround by using .getDisplayValue instead of .getValue - it does change the cell value into a string, so if you need to do further manipulations that are dependent on the value being a number or something, obviously, this fails.
I overwrite the value for the problem cell in my array before passing it to .appendRow
//getting the values
var values = s.getRange(row,1,1,lastCol).getValues()[0];
//brute force crushing of problem value
values[5] = s.getRange(row,6).getDisplayValue();
I have used this VBA code to convert columns into pipe separated format. However, the data contains numbers in scientific notation (eg 2.000000e-01) which Excel automatically converts into 0.2 which I don't want.
I have tried changing this code:
var = Application.Transpose(Application.Transpose(rng.Value))
into
var = Application.Transpose(Application.Transpose(rng))
or even
var = Application.Transpose(Application.Transpose(rng.Text))
neither of which work. I've also tried formatting the cells all to Text (the macro then gives a Value error) or even switching off scientific notation.
How can I convert columns into a single, pipe-separated column without losing scientific notation?
Sample columns:
SAMPLE TEST 2.000000e-01 2.000000e-01
You want to concatenate text values using either the CONCATENATE function or the & operator. For the scientific notation, you want to use the TEXT function. Excel is actually storing the numbers as 0.2 but then displaying them in scientific notation.
The help for the TEXT function says:
Syntax: TEXT(value, format_text)
Display scientific notations:
To display numbers in scientific (exponential) format, use the following exponent codes in the format_text argument.E (E-, E+, e-, e+) Displays a number in scientific (exponential) format. Excel displays a number to the right of the "E" or "e" that corresponds to the number of places that the decimal point was moved. For example, if the format_text argument is "0.00E+00", Excel displays the number 12,200,000 as 1.22E+07. If you change the format_text argument to "#0.0E+0", Excel displays 12.2E+6.
So for your example, assuming the values are in cells A1:D1, use:
=A1&"|"&B1&"|"&TEXT(C1,"0.000000E+00")&"|"&TEXT(D1,"0.000000E+00")
Or in VBA, you can use the Text property of the Range object to get the contents of the cell as they are displayed. If the column width is too narrow for a date and the column shows "########" then that is what the Text property will return.
EDIT: I misread the post. This answer is for separating text from one column into many columns. OP is trying the reverse.
You use the Excel Text to Columns wizard (on the Data tab, select Text to Columns). Select your data, then run click the menu. When you get to step 3, tell Excel that you want to keep the column as Text.
If you need this done using VBA, then use the macro recorder to get the initial code which you can then tweak to fit your needs.
I want to create a makro in Excel which performs - after pressing a button - the below. I attached some dummy data that is formatted like the actual sheet.
There are several data blocks that are seperated by headlines in Sheet 1. From these headlines, I want to get a string of numbers and put it into column S for each line with data below that heading. In line 6 the heading says "2000", thus lines 8-19 should have a "2000" in column S and so on. The number I want to get is always after the word "Monthlyaccount" but the lenght of the number can be different - from 1 to 7 digits.
For lines where no data is given (data lines might be recognized by looking if in A is a valid date given) there should just be "ERR" instead of the number.
Can anyone help out?
Thanks so much upfront!
Say the string (in cell A1) contains "Monthlyaccount" followed by a blank followed by a number followed by another blank. To extract the number, use:
=--LEFT(MID(A1,FIND("Monthlyaccount",A1)+15,9999),-1+FIND(" ",MID(A1,FIND("Monthlyaccount",A1)+15,9999)))
This does as requested. Paste the following into S3 and drag down
=IF(AND(ISNUMBER(RIGHT(A2,4)*1),ISNUMBER(RIGHT(A3,4)*1)),S2,IF(ISNUMBER(RIGHT(A3,4)*1),LEFT(RIGHT(A1,LEN(A1)-FIND("Monthlyaccount",A1)-14),FIND(" ",RIGHT(A1,LEN(A1)-FIND("Monthlyaccount",A1)-14))),"ERR"))