473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

change 0 value to "-"

25
hi...

can access change the 0 value in my crosstab into "-" character.
i want that character appear in my report not as "0" but "-'

thanks
Feb 20 '09 #1
9 2014
Dan2kx
365 100+
in your value field you can put something like this:
Expand|Select|Wrap|Line Numbers
  1. Count: nz(Count([Table.Field]),"-")
  2. 'as an expression
that should work i believe.

Dan
Feb 20 '09 #2
Stewart Ross
2,545 Expert Mod 2GB
If you really mean in a report (and not just for display in the crosstab query itself) you can always apply a custom format using the Format property of the textboxes concerned. The format property can have four sections, separated by semi-colons: format for positive numbers, negative numbers, zero values, and null values.

If you needed two decimal places for positive and negative but '-' for zeros the custom format of the textbox would be

0.00;-0.00;-

The Nz function will only convert null values, not zeros, and anyway has a disadvantage in that it will convert the number displayed to text - which will spoil subsequent attempts to display or format the number in any report based on the query.

Similarly, using, say, the Format function to display custom formatted data in a query also converts the results to text - an annoying limitation which means it is better to apply formatting as the very last step in the chain of processing, preferably within the form or report used to display the data.

-Stewart
Feb 20 '09 #3
dbdb
25
thank you guys...
it works.
Feb 20 '09 #4
Dan2kx
365 100+
@Stewart Ross Inverness
I presumed he would be using his crosstab to count
@Stewart Ross Inverness
Would that be a problem?
Just curious

Dan
Feb 20 '09 #5
Stewart Ross
2,545 Expert Mod 2GB
Hi Dan. Text values that look like numbers cause all sorts of problems. One obvious one is that text values don't sort the same way as numbers
(for example, a text sort of the numbers 1, 10, 11, 20 and 100 is
1, 10, 100, 11, 20). Another, as I mentioned, is that text values cannot be custom formatted in a form or report - so no displaying as currency values if this was required, or specifying decimal places and so on.

The crosstab may well use count - but there again it could have been max, min, last, first, and so on. We don't know (as we weren't told in the question) - so it is safest not to make assumptions about the underlying function when Count is just one of many possibilities.

The poster did mention that the requirement was to substitute for zero values. That is all we had to go on. Ask yourself how Count could ever be the function directly returning a 0 value in a crosstab? Count will either return a value of 1 or greater, or a null if there are no rows to count. It can never itself return a 0.

Any null values returned by the pivot function can be replaced with 0 using Nz - but wrapped in a conversion function to ensure its return value remains a number and not text:

CLng(Nz(Count([somefield]), 0))

Coming back full circle, since this 0 is a number the way to display '-' instead of the 0 is to use the custom formatting as recommended!

-Stewart
Feb 20 '09 #6
NeoPa
32,556 Expert Mod 16PB
Unlike most aggregate functions, Count() actually does return a 0 (rather than Null) when there are no matches. This effects what Stewart said very little however. The points are just as valid. Keep it numeric until you have to, as you have little idea what may want to treat it as numeric in other situations. After all, queries are used as the input to many different objects, including other queries.
Feb 22 '09 #7
Stewart Ross
2,545 Expert Mod 2GB
Hi NeoPa, and thanks for the clarification. In a crosstab query the result of Count(), Sum() etc pivoted on another field will be null if there are no matching rows. The pivot result is like what happens with an outer-join when there are no matching rows to return on the 'optional' side of the join - any fields listed from the optional side return as null for that row.

Here's a test query that represents the minimum possible crosstab - one row header field, a pivot column, and a value. In the example there is a pivot value for gradeID of 'G8' that occurs in just one row, that for ID 'B6'. Note that all other rows show a null value, not a zero, for that entry:

Expand|Select|Wrap|Line Numbers
  1. TRANSFORM Count(*) AS Result
  2. SELECT id
  3. FROM gradecounts
  4. GROUP BY id
  5. PIVOT gradeid;
Result
Expand|Select|Wrap|Line Numbers
  1. id    G7    G8
  2. B1     1    
  3. B2     2    
  4. B3     1    
  5. B4     1    
  6. B5     3    
  7. B6     1     1
Anyway, you have captured exactly what I wanted to say about keeping values numeric for as long as possible before doing anything that changes them to some other type.

There are useful tips on crosstabs on Allen Browne's site, at http://allenbrowne.com/ser-67.html.

-Stewart
Feb 22 '09 #8
NeoPa
32,556 Expert Mod 16PB
I do beg your pardon Stewart.

I thought it was unlikely that you'd make such a mistake. I should have known better.

I must admit that cross-tabs are something I never use, and consequently have very little experience of.
Feb 22 '09 #9
Dan2kx
365 100+
I made the same mistake and assumed the OP was requesting something i already did in one of mine.

Dan
Feb 22 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nick Calladine | last post by:
Is this possible to ... I wish to get the value of a dropdown select but gets is indexable value (dont know if that is the right term) if that is possible (the position it assigned get assigned...
2
by: Rick | last post by:
I have an XML document that is generated from Infopath, I need to change the value of a namespace that is defined in a node in the form: <xsf:xDocumentClass "xmlns:my=valuehere">. when i navigate...
2
by: Richard | last post by:
Hi, I have a DateTime picker control on a form. The datetime picker control is data bound to a column in a DataTable. Yes I know about bound DateTime pickers and DBNull and etc. so no troubles...
10
by: rob | last post by:
I have a class that among others exposes a string property "Date". The date in this property is stored in the form yyyymmdd. Now I do the following 1) Generate a DataGridViewTextBoxColumn column...
3
by: John Smith | last post by:
I'm looking into this peace of code: protected void DropDown_SelectedIndexChanged(object sender, EventArgs e) { DropDownList list = (DropDownList)sender; TableCell cell = list.Parent as...
2
by: John Smith | last post by:
Will this line of the code: item.Cells.Text = "Some text..."; change only DataGrid visual value or it will also change value in the DataSource? How can I change value in DataSource? ...
2
cassbiz
by: cassbiz | last post by:
I may be in the wrong forum so Ronald don't shoot :) In my code I have an option box to choose a number - works fine. I want to carry over the new value to another field to do a recalculation. ...
45
by: Zytan | last post by:
This returns the following error: "Cannot modify the return value of 'System.Collections.Generic.List<MyStruct>.this' because it is not a variable" and I have no idea why! Do lists return copies...
5
by: raha | last post by:
hi. Is there any body to help me? I am writing a web program. I have some forms. each form have some controls and users can edit the controls. finally they can save their forms. I would like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.