SSRS 2005 Number formatting int and double within one field - sql-server

I am using SSRS 2005. The issue is I would like to place, in numbers so if number is 23455 it should be displayed as 23,455 I know how to do this I have two data types in this field int and double. What I did to accommodate it is changed the numbers to strings but if I extract them to Excel they show green triangle.
To eliminate green triangle in Excel I used CDEC() function which converts the string to number by doing this I loose , in the numbers.
I was wondering if it is even possible to place a comma within the field which has two different datatypes i.e. double and int.

Strings are not your friends! Don't convert numbers to strings.
You should set the format of your cells (textboxes or placeholders) to include the comma. Right click on a text box or placeholder to get the properties dialog. Use the Number pane to format. (You can set this exact same setting in the properties pane as well.
Using these will let the number stay a number in the cell, and will export the formatting to Excel without the conversion to a string.

Related

Variant array to Range, set range data type to match accordingly?

When using a variant array in Excel, it will automatically set each value to the appropriate data type like string, doubles, dates, etc.
When I move the entire array to a sheet, the sheets data types wont change with it. If the data is a Date, it will display serials if the range is set as a Text/General. If set to Date, any doubles will look like ####.
I also have some formulas in my array, so setting the range to a Text will cause the formulas to not calculate.
I'm wondering, when pasting the array, is there a way to also set each cells data type to match the data type stored the array?
The output of the array is used to copy and paste into another application, so having the proper format show on the excel would reduce manual work to adjust them afterwards.
Thank you in advance.
The VarType function returns a value associated with a data type. The .NumberFormat property of a range can be used to set the display format correspondingly. This takes a string so it can be a little tricky to enter correctly. The best way to determine this is to set the cell to the format you actually want and then switch to custom format (in the standard format cells right click menu). The text you see in the bar is what you want in the code.

SUM with IF conditions for cells containing both strings and numbers

I've got a bigger table with one column that I want to focus on, containing designation and a number. I want to simply sum the numbers that meet the criteria based on a designation.
For the simplification, I made an exercising sheet (on the pic) where I split second column into two - one string and one numeric. Since my file is quite large with many columns that would need this it would be inconvenient.
In the left column it's easy to solve the problem, it could be even easier with simple SUMIF function, but an array SUM(IF... function is, at least I think, only viable option here.
So I solved the first table with array function, but what confuses me is how to modulate the TRUE statement. Simple replacement of C:C
with
VALUE(MID(F:F;4;4))
which would format my cells to get the numbers from string does not work that way - returns zero in E12 field. F12 is just application of string to number for last cell, F10.
THIS formula does not work, even adapting to different versions of the tool.
I could use VB but if possible anyhow I would like to avoid it since parts will be shared on mobile phones.
Any ideas? Thanks a lot!
Left table was split, right original format
The array formula which you used can be replaced by the SumIf formula like below...
=SUMIF(B:B,"B",C:C)
Also without the helper column, you can use the Sumproduct formula to achieve the desired output.
But don't refer the whole column in the formula like in the above SumIf formula.
Try this..
=SUMPRODUCT((B1:B10="B")*MID(F1:F10,FIND(",",F1:F10)+1,255)*1)
Change the ranges as per your requirement but remember to make them equal in size.

Three variables (columns) to be combined in one variable (column)

demo data
Either in Excel or in Statistical Package for the Social Science:
To combine the three columns into one and to be able then to calculate the statistics of the column. Mean, Median, Mode frequencies and all these.
I too have no idea why you want what it appears you do but assuming your values are numeric to two decimal places then with Excel I suggest in D1 and copied down to suit:
=TEXT(100*A1;"000")&TEXT(100*B1;"000")&TEXT(100*C1;"000")
this results in text strings. Should you want numeric output for further processing then a double unary can be applied:
=--(TEXT(100*A1;"000")&TEXT(100*B1;"000")&TEXT(100*C1;"000"))
In the latter case Excel will automatically strip any leading zeros. In the former case (should a number less than 1 be a possibility) the TEXT function preserves leading zeros.
Multiplication by 100 is to scale up the numbers to remove the decimal separators.
If the numbers are text then they may be concatenated and the commas removed with SUBSTITUTE:
=SUBSTITUTE(A1&B1&C1;",";"")
The above results in text strings which again may be converted with the double unary operator.

Format text in flow document table cell

I have a program that creates a table, adds it to a flow document along with table cells that are populated with text. Everything works great with one exception. One column of cells in the table displays costs and they have been formated as follows:
cellValue = "$" + string.Format("{0:##,#.00}", int.Parse(cellValue)).PadLeft(22 -
cellValue.Length);
As it turns out, with this formatting numbers like $ 11,111 take up a different width then numbers like $ 10,000. I would guess because the font is not equal width for each character.
What I would like to do is be able to display the costs just like the are when in an Excel spreadsheet when formatted as Accounting (ie the dollar sign is left hand justified, the numbers are right hand justified and the numbers are lined up from cell to cell).
Example:
$ 10,000.00
$ 11,111.11
If someone knows what formatting to apply to reach this goal please let me know.
This is probably too simple but at a guess I would use fixed font for the cell like "Courier New" so that all the characters are the same width and would align up. The downside of this is that "Courier New" is not the most elegant font to use.
I am sure Excel uses a much more sophisticated mechanism for aligning numeric values.
Maybe you should use something that better mimics a spreadsheet than a table in a flowdocument.

VBA Excel Percent format in an array

Is there a way to save a specific format in an array? I'm trying to find the percent difference and the regular difference between numbers in two separate grids. I can do these things individually but when I try to put the answer in the same worksheet I run into errors.
As of now, I calculate the percent difference and then I select the grid where all my answers are and change the style and number format. However, when I try to show the difference as well (such as "percent difference / difference" the program returns a long decimal for the percent difference. I know that the reason is because the number format and style format are not saved into the actual array but I can't figure out how to fix it.
I've tried the following:
Changing the format right before I create the slash and the difference
Assigning the answer array to the current values in the active cell (the values are still the decimals, not the percent counterparts)
Calculating percent difference and the difference, then changing the format (this was more of a faint hope than an actual attempt to change anything)
I can't remember if I tried anything else but I know it failed horribly.
***** Example ******
The user will send my program to a specific workbook that has two sheets with a grid of numbers on them. These grids have the exact same dimensions. My program will calculate the difference between these sheets (Sheet1 - Sheet2), the percent difference ((Sheet1 - Sheet2) / Sheet2), and both. These three calculations are presented on three separate sheets that the program creates. All of the numbers that the program produces will be in the cells that correspond to the cells where it got the numbers in the first place. Also, the third sheet (both percent and difference) are seen as "percent difference / difference". Now here's an example with test numbers.
Grid 1
12.0 5.0
2.0 10.0
Grid 2
6.0 7.0
1.0 3.0
Diff
6.0 -2.0
1.0 7.0
Percent Diff
100.00% -28.57%
100.00% 233.33%
So the "Both" tab would look like:
100.00%/6.0 -28.57/-2.0
100.00%/1.0 233.33%/7.0
Sorry for not making this more grid like. I wasn't sure how to present it.
Thank you
Not sure if I completely follow, but I think you may just need the range object ".Text" method:
dim rgNumValues as Range ' cells formatted as 12.0, 5.0 etc
dim rgPctValues as Range ' cells formatted as 100%, -28.57% etc.
Then to create new cells that marry both formats
dim rgNumAndPct as Range
rgNumAndPct.Cells(1,1) = rgNumValues.Cells(1,1).Text + " / " _
+ rgPctValues.Cells(1,1).Text
' creates cells w string values like "12.0 / 100%", "5.0 / -28.57%" etc.
The ".Text" method extracts the visible string from your NumValues and PctValues rather than the underlying numeric value. Just rewrite as a loop to do all the cells. For a very large range, you can speed up by creating NumAndPct values in a variant array and assigning the array to the target range.
If you are doing this with code in vba you would use the Format function for each item and append the cells in a similar fashion. If a simple formulaic version would work, something like this, substituting the sheet names in where needed.

Resources