SSRS export to Excel force number to be a text value - sql

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.

Related

Formatting Unbound Text Box with Value from ComboBox

Novice / Intermediate Access User.
I have a form in MS Access (O365 ProPlus) which has a ComboBox based on six column query.
AfterUpdate, I want to pull the Value from column of the ComboBox and populate it in an unbound text box. However, the formatting needs to be Currency and it's not carrying over correctly from setting the Currency formatting in the Form Properties Field for the Textbox.
I have tried formatting in the Control Source property when pulling the ComboBox column values that way which had limited success. It displayed the Currency format but when I try to use the value in the textbox later to be used in a calculated (Sum) total value field elsewhere on the form, it is only recognized as text.
The TotalValue Textbox only concatenates the textbox(es) with currency dollar signs.
Combobox1_AfterUpdate: ()
Textbox1 = Combobox1.Column (2)
Textbox2 = Combobox1.Column (3)
Textbox3 = Combobox1.Column (4)
TotalValueTextbox = Textbox1 + Textbox2 + Textbox3
Expected results are one number adding up numerical values of the aforementioned text boxes. Instead I get number1number2number3 as if I am concatenating text strings.
Currency format (if it works in preceding text boxes) comes with the dollar sign but decimals don't carry and it concatenates the values in lieu of adding them.
I even tried adding a tertiary test textbox and made its Control Source value equal to 12 times (arbitrary value) of one of the Textboxes and it multiplied correctly, but when multiple text boxes are involved using sum calculation as listed above it didn't work.
Problem is, that a combobox always returns text. If you feed it with numbers or currency, these will formatted using your default settings.
So, add some extra columns to hold your amounts with no currency formatting but forced to text using Str. In your source query of the combobox, add three columns:
Column5: Str([Amount1]
Column6: Str([Amount2]
Column7: Str([Amount3]
Then use convert the values to numbers with Val:
TotalValueTextbox = Val(Combobox1.Column(5)) + Val(Combobox1.Column(6)) +Val(Combobox1.Column(7))
Finally, specify the Format property of TotalValueTextbox as Currency and, in Combobox1, set the column width of the extra columns to 0 (zero).
Using Format() function with Currency parameter results in a string with a $ sign character. Plus (+) character is a concatenation operator left over from old BASIC as well as arithmetic operator. Concatenation will have priority in some situations, as you encountered with textboxes on form.
Instead of formatting data on form, put $ in a label next to textbox.
Otherwise, calculate with direct reference to combobox columns.
= Combobox1.Column(2) + Combobox1.Column(3) + Combobox1.Column(4)

How can I convert columns into a single, pipe-separated column without losing scientific notation?

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.

Flexible Data Label Formatting

I'm hoping to add custom data labels to a stacked bar chart in Excel 2010. Each bar will have a label value pulled from a value in the sheet which is not necessarily equal to the height of the bar itself.
The sheet I'm making is a template and has drop-down selections to change the units of the data. For example: $MM with 1 decimal point, K with 2 decimal points, $ with 0 decimal points, etc... I'm running into an issue formatting the labels to match the data formatting selections. I've tried two approaches:
Formatting the data labels themselves using VBA. Partial code below for $K with one decimal:
`With ActiveChart.SeriesCollection(x).Points(y)`
.DataLabel.Text.NumberFormat = "$#,##0.0,"
Unfortunately, the labels don't seem to read the commas and divide by one thousand, so I can't accurate display thousands or millions. A value of 1000 in the above code will display as $1,000.0 instead of the desired $1.0.
Format the values in the worksheet, and then just read them with VBA. Basically, I use conditional formatting to properly display the values on the sheet, and then read them with .DataLabel.Text = Cells(r,c)
Unfortunately, though the data is formatted correctly, the values are unchanged and the labels display with no custom formatting at all.
Is there any reasonable way to achieve my goal? I'm hoping there's a way to either (1) make commas count when changing data label number formats or (2) change the actual values of the data in my sheet based on the formatting drop-down selections (instead of just giving them custom formatting which leaves the value unchanged).
Thank you,
Lance
I think the words "conditional formatting" are your issue here: I've had problems with VBA reading the underlying format of a cell when it's conditionally formatted (admittedly, my issue was with colour, rather than number format, but I expect the reasons for it not working would be the same).
If you adopt your second approach, i.e. relying on the worksheet's format using the chart's "Linked to source" option, then on a trigger of when the drop-down option is changed, you could use VBA to set the format on the worksheet instead of using conditional formatting - then the chart would pick up whatever format you're using.
Please try this:
?Format(1000,"$#,##0.0,")
$1.000,0
?Format(1000,"$#,##0,.0")
$1,0
?Format(1234,"$#,##0,.0")
$1,2

Number to be copied from cell with the same number format and show it as a label for a shape without any change in the number format

I have a cell in excel which contains a value, lets say 100000.
Now i want this value to have commas in between them to represent the thousands and millions i.e. 100,000. I can do this by changing the number format in the home menu.
Now i want this value to be copied from that cell and paste it as a label for a shape. When i am doing this the commas go away showing me just the numbers.
I want it to happen through VBA but this is not happening in excel itself.
Does anyone have a plausible solution for this?
In range object use Text property, like this:
Sheet1.Shapes(1).TextFrame.Characters.Text = Range("A1").Text

Format Text to Number format in Report Builder 3.0

I am working with 4 fields in Report Builder 3.0 in which I am trying to format as a number with the corresponding comma. When I use the number format in the Text Box Properties nothing happens. When I export this report to Excel the field has to be converted to a number as it is being exported as a text field.
Do you have any suggestions as to how I can change the formatting in the report itself?
Thanks for your time!
If I pull data from Oracle using an openquery I get the same issue. To resolve:
When you have the Text Box Properties box open, select the function key by the Value.
In the expression, add "Int" at the front of the string with () on each side of expression. (This converts the value of the expression to an integer)
Ex: =Int(Fields!Count.Value)
Close the expression box after making these additions and select "Numbering" in Text Box Properties to format the text box accordingly.