MS Access VBA Cross tab report legend sort order - ms-access

The problem is hard to explain ,
I have an access report with a stacked bar chart to show the percentage fills over time like the one in this example : Click here
The legend for the chart i have is a number followed by the name, for e.g
1-Mango
2-Apple
3-Banana
etc
I want to sort this according to the above format but when i have more than 10 items the 10-Pineapple comes before 1-mango when it should appear after 9-somefruit .
The underlying query for the access report uses a Cross Tab query in which the items are created as
Column heading:[PrefixPriorityNumber]&"-"&[FruitName]
I even used the Sort:Ascending but it still doesnt affect my custom ordering that i wanted to show.
I also tried to google "sorting alpha numeric strings" but this is clearly more than that.Any assistance is appreciated

The problem is you are getting a text sort. You need to format the prefix number.
Column heading: Format([PrefixPriorityNumber], "00") & "-" & [FruitName]

Either use another digit, as Remou suggests (01 instead of 1) or start using letters. A > 9, B > A, etc.

Related

How to generate numbers for showing sequence in SSRS also it should get rearrenge when any field inbetween is missing

I am facing problem in SSRS report for showing sequense numbers as given in image.
when I searched for this issue I got solution as -- RowNumber("DataSetName")
but problem with this is, it generate numbers like 1,2,3..., but I want these numbers in following forms- 1.1, 1.2 or 1.1.1, 1.2.1.
And another problem for me is above function will work if I am having multiple rows in dataset and that dataset is bind with table to show its data, but In my case I am getting all data in single row and out of that I am showing values in textbox using expressions and if that value is empty I am hiding that textbox.
so I am not getting any solution to show sequence number in textbox along with text and how I can rearrenge that numbers if my inbetween textbox is hidden because of no data.
Please provide me solution for above probem.
Image for reference -
Example of data is :
From above table values from "Subheading1" And "Subheading2" will show inside "Heading first" and "Subheading3" And "Subheading4" will show inside "Heading second".
You can concatenate row numbers as strings as follows:
=RowNumber("HEADING") & "." & RowNumber("SUBHEADING")
To ensure numbers are consecutive remove the relevant rows in the source dataset instead of hiding them in the tablix.

SSRS number format expression showing unexpected results

I have a table that contains metric data for various business units in our organization. There is one column that contains the KPI measurments. I've created a report to display each business units KPI's. Some of the metrics need to be displayed as whole numbers, others need to be displayed as percentages.
I created an expression to handle the multiple formats. The problem I'm having is with the percentages. For example one of the numbers (which should be displayed as 93.74%) appears as 939474%. If I remove the expression and set the format to percentage using the text box properties, the number displays as 93.74%.
Here is the expression I'm using:
= IIF(Fields!KPI_desc.Value like "*Rate",
Format(Fields!Value.Value,"0.00%"),"0")
Any suggestions would be appreciated.
Thank you
I guess you put this into the Format Expression so that it will return the result like integer. Actually you just need to put this expression into textbox directly.
= IIF(Fields!KPI_desc.Value like "*Rate", FormatPercent(Fields!Value.Value,2),"0")

Way to add a calculated number of X's to a form input?

I have certain product codes with varying number of letters/digits e.g. 53HD6J, HH88WBD3 (varies between 5 to 10 letters/digits). In order for our barcode to scan these correctly there has to be 13 letters/digits. I don't want to make the user to input -XXXX after each code but rather have Access calculate the difference between 13 and the length of the code and fill the remaining with a X's. Is this possible either by vba or and expression?
I currently am using about 6 IIFs in one formula to fill remaining blanks with X's but hoping there is an easier way.
I have a form to enter in the batch number (product code). Once that form is submitted it links to a report that is printed. On the report are those batch numbers (53HD6J, HH88WBD3). The spot I want to have this feature is in a text box right next to the codes where Access determines the length of the codes and computes the remaining X's to add. This is in barcode font so this text box is where the 53HD6JXXXXXXX would go. Hope that clears it up!
So I have that part figured out. My problem now is my barcode font reads the text no matter what and translates it still so barcode shows up when the batch number is blank (I have four spots for batch codes to be inputted). So what I had before was =IIf([Text31]="",""&[Text31]&"","") which seemed to work. Hopefully I can continue this with the new formula. If that's unclear let me know.
**(The "" & & "" is so the barcode can be scanned).
My formula was wrong right above with the IIf. I figured it out! Forgot I had used ' Like "*" '. Thanks!
You can do what you want with String() and Left().
Here is an example from the Access Immediate window:
product_code = "53HD6J"
? product_code & String(13, "X")
53HD6JXXXXXXXXXXXXX
? Left(product_code & String(13, "X"), 13)
53HD6JXXXXXXX
Based on the update to your question, I think you can use that approach for the Control Source of a text box where you want to display the "expanded" product code.
Pretend your report has a text box named txtProduct_code where the raw product code, such as 53HD6J, is displayed. And there is a second text box where you want to display that value with the required number of X characters (53HD6JXXXXXXX).
Use this as the Control Source property of that second text box:
= Left([txtProduct_code] & String(13, "X"), 13)
Alternatively, you could make it a field expression in the report's Record Source query.
SELECT
product_code,
Left(product_code & String(13, "X"), 13) AS expanded_product_code
FROM YourTable;

SSRS custom number format

I am go to generate an excel file from SSRS, and
I want to format the number like this...
15 is displayed as 15
14.3453453 is displayed as 14.35
12.1 is displayed as 12.1
0 is displayed as 0
1 is displayed as 1
I can apply this in Excel but unable to apply in SSRS
[=0]0;[=1]1;0.##
Does anyone can suggest another way for me? Thanks!
am assuming that you want to know how to format numbers in SSRS
Just right click the TextBox on which you want to apply formatting, go to its expression.
suppose its expression is something like below
=Fields!myField.Value
then do this
=Format(Fields!myField.Value,"##.##")
or
=Format(Fields!myFields.Value,"00.00")
difference between the two is that former one would make 4 as 4 and later one would make 4 as 04.00
this should give you an idea.
also: you might have to convert your field into a numerical one. i.e.
=Format(CDbl(Fields!myFields.Value),"00.00")
so: 0 in format expression means, when no number is present, place a 0 there and # means when no number is present, leave it. Both of them works same when numbers are present
ie. 45.6567 would be 45.65 for both of them:
UPDATE :
if you want to apply variable formatting on the same column based on row values i.e.
you want myField to have no formatting when it has no decimal value but formatting with double precision when it has decimal then you can do it through logic. (though you should not be doing so)
Go to the appropriate textbox and go to its expression and do this:
=IIF((Fields!myField.Value - CInt(Fields!myField.Value)) > 0,
Format(Fields!myField.Value, "##.##"),Fields!myField.Value)
so basically you are using IIF(condition, true,false) operator of SSRS,
ur condition is to check whether the number has decimal value, if it has, you apply the formatting and if no, you let it as it is.
this should give you an idea, how to handle variable formatting.
Have you tried with the custom format "#,##0.##" ?
You can use
=Format(Fields!myField.Value,"F2")

SSRS- charts colour coding

I have SSRS solution for SQL 2005 and 2008.
I am showing output in the form of chart- column chart with each column representing different database.
Is there a way to display each column in different color?
Regards
Manjot
You can use a formula to set the colour of each column, but that would work best if you knew what the individual series values ('databases'?) were going to be.
Right-click on your chart and bring up its properties. Now switch to the Data tab and select the first item in the Values list. Click the Edit... button to show the properties for the values (the columns) in your chart. Over on the Appearance tab there's a Series Style... button which takes you to another dialog.
On this new Style Properties dialog, switch to the Fill tab. That's where you set the colour for each of your columns. This can be a formula, so you might make it something like:
=Switch(
Fields!Database.Value = "master", "Blue",
Fields!Database.Value = "msdb", "Red",
"Green")
If you don't know in advance which 'databases' are going to be represented on the chart, this method won't work very well. In that case you might be able to come up with a formula which hashes the database name and comes up with a colour to match. That sounds like an interesting challenge, so add to your question if you need help doing something like that.
Edit
I just got a hash-based-colour-scheme working. It's a pretty nasty piece of code, but it did manage to get me a unique colour for every (string valued) column. Perhaps someone can come up with a better algorithm and post it here. Here's mine:
="#" & left(Hex(Fields!Database.GetHashCode()), 6)
So that's getting the HashCode for the string (a numeric value) and converting it to hex, then taking the leftmost six characters and prepending it with a "#" sign. That gives us a string that looks like a colour value (eg #AB12F0).