SSAS - How to configure format number for calculated measures? - sql

I created a calculated measure in order to allow user to display the operating margin about sales.
ROUND([Measures].[Total] - [Measures].[Total Cost],2)
It works well, however I get an error when I try to retrieve the data in Excel / PowerPivot.
In fact, It displays values by using the ",." format to separate decimals and my format is " ,). So how to configure to change this behavior in SSAS because Excel cannot format the number due to a "unknown type" (it cannot parse the number).
This an example of decimal conversion from US to French format :
1,000,000.00 (US) -> 1 000 000,00 (France)
99.99 (US) -> 99,99 (France)
OK I could replace the "dot" by a "comma" directly in Excel but it's not a good practice and the objective is to simplify the PowerPivot usage.
Thanks !

In your SSAS project you can use "Format string" field to specify the format:
In the code it looks this way:
CREATE MEMBER CURRENTCUBE.[Measures].[ASP]
AS [Measures].[Amount]/[Measures].[Units],
FORMAT_STRING = "$#,##0.00;($#,##0.00)";
Use either manual string to create exact look or if all your environments are properly set up as French locale, there is a standard "Currency" format string which also might work in your favor.

Related

Formatting duration for display

In a SAP database there are values formatted as PxDTyH where x is the number of days and y is the number of hours. A value like P2DT0H is 2 days + 0 hours. I can see that via SE16:
Unfortunately, this is exactly displayed like that to the user, "3" corresponds to the index in the database (not seen in the screenshot above).
I'd like to see it displayed
without the index (changing the options "show keys within drop-down lists" did not have an effect)
instead of the technical name P2DT0H I'd like to see "2 days and 0 hours" (or similar)
Is there a way to process the data before it gets displayed in the combo box? The developers can't change the format in the database because it would change the API.
FYI: I'm just a tester, I don't know how to code in ABAP, but from knowledge of other programming languages, I'd say that the data can be converted before it's displayed. I don't need a fully-fledged answer, just a pointer to a SAP hook or event which enables writing a conversion function.
Probably, conversion routines can be an option for you. What you should do is to:
Take your domain (which is used for PxDTyH values) or create new one specially for this.
Create FM with name CONVERSION_EXIT_%NAME%_OUTPUT, and put conversion logic in there. Mandatory parameters INPUT and OUTPUT should exist.
Enter the %NAME% into Convers.routine field in domain properties.
Enable Check conversion exits checkbox in user parameters.
More info is here.

IcCube - Formatting problems

I have two problems regarding the formatting of my table:
All of my Dimensions are completely uppercase. If I launch the query in the MDX IDE, I get results as expected, but in the reportingtool (/icCube/doc/ic3report) everything is uppercase. Unfortunately I couldn't find any setting to change that yet.
I would like to display my number formatted in the german style (, as decimal sign and . as thousands separator). If I put in my query FORMAT_STRING = '0.000,#' of yourse the system doesn't know, what is meant. Is there a way to tell, how I would like to see the numbers?
Thanks for your help
~Ulrich~
Can you be more precise about the 'faulty' widgets and what is badly displayed (dimension name, member name, etc). The Web reporting should not change the case of the model definition.
The thousand separator used is defined by the locale not by the FORMAT_STRING definition. You should define the locale of the user as German. Note, if no locale has been defined then the icCube server (i.e., Java process) locale is used.
Note: in the FORMAT_STRING definition, the '.' represents the decimal separator and the ',' the thousands separator. I believe your example should be: '0,000.#'. More details can be found here.
Hope that helps.
After a restart of the IcCube Server the right locale is now recognized and this part is working.
As for the words all in capitals I found out, that this happens, if no style is chosen in the widgets/filters. Once I chose a style, I had everything written as it should.

Formatting Short Text as Numbers

I've got a column called Amount, with a lot of numbers looking like this:
67000.00000000000000000000
Some of the columns have 2 numbers after the decimal that need to be retained.
Which should amount to $67,000.00
But my problem is, when I format it into currency or numbers, I get MUCH larger numbers than i would like, looking like this:
6.700.000.000.000.000.000.000.000,00
How can I get it into the right format?
Edit: For this scenario, the user was using ACC2013 and the Field Type was Short Text. The method of conversion that succeeded was : CCur(Val(FieldNameHere))
CCur(YourFieldName)
This will convert it to a currency format.
CLng(YourFieldName)
This will convert it to a long integer format. (It will cut off the decimals)
If you're looking for a reference, Microsoft has a few examples and goes into brief detail about some of these conversion functions.
CCur(Replace("67000.00000000000000000000", ".", Format(0, ".")))
You have to replace point symbol to actual decimal separator before conversion. Because you can't know actual seprator, choosen in regional settings, you have to find it out - and such Format() operation does dirty work.

ireports disregarding my settings

I am currently using an XML datasource and I have the date patterns as well as the number pattern set up as dd/mm/yyyy and #,##0.00 respectively, however the data I am pulling from the fields with Xpath is not following this pattern.
an example of a date I am catching is : 2014-02-12 16:00:15 while a price will appear as 40.0000000000.
I also clicked on the aformentioned fields and went into properties, and under pattern I changed it to currency as the numbers refer to prices and set decimals to 2, the problem remains.
After some trial & error I came to this method that worked wonders.
new Double(Double.parseDouble($F{Precio_unidad-price_unit}))
setting this in the TexytFieldExpression will actually do what is neccesary, the report now prints the correct number of decimals.

VisualBasic Month function inconsistency

I'm working in a web application using VB.NET. There is also VisualBasic code mixed in it, in particular the Date variable and the Month function of VB.
The problem is this part:
Month("10/01/2008")
On the servers, I get 10 (October) as the month (which is supposed to be correct). On my machine, I get 1 (January) (which is supposed to be wrong).
Two of my colleagues (on their own machines) get different answers, one got 1, the other got 10.
The question is, why is this so?
On my end, I can solve the problem by using .NET's DateTime's Parse (or ParseExact) function to force everything to be "dd/MM/yyyy" format. This works. I'm just wondering why there's an inconsistency.
Extra info: I know the parameter for Month function is supposed to be a Date variable. The code used a string as parameter, and Option Strict was off, and the developers mainly let VB do its own conversion thing. (Legacy code maintenance has a lot of inertia...)
If it helps, the version of Microsoft.VisualBasic.dll on the servers is 7.10.6310.4 (under the Framework folder v1.1.4322). The version on mine (and my 2 colleagues') machine is 7.10.6001.4.
Edit: Regional settings for all machines already set to dd/MM/yyyy format (short date format).
This normally has to do with the regional settings, and more specifically the date/time formats. If you set these formats so that they are all the same on the machines you're testing on, the results should be consistent.
Your idea of using ParseExact is definitely the better solution to go with, IMHO.
This is because the runtime has to convert your given value "10/01/2008" which is indeed a string implicitly to the DateTime datatype.
When converting strings to dates and the other way round, the string format depends on the locale settings of windows.
See this link on msdn.
In this article a way to specify a date literal which is independent of your locale settings:
Just enclose the date with the sign # and specify it in the form mm/dd/yyyy:
So the code
Month(#10/01/2008#)
should give you the answer 10 on any machine.
Ther a two more worarounds given in that msdn article:
1. Use the Format Function with predifned Date/Time Format
To convert a Date literal to the
format of your locale, or to a custom
format, supply the literal to the
Format Function, specifying either
Predefined Date/Time Formats (Format
Function) or User-Defined Date/Time
Formats (Format Function). The
following example demonstrates this.
MsgBox("The formatted date is " &
Format(#5/31/1993#, "dddd, d MMM
yyyy"))
2. Use the DateTime-Class Constructor to construt the right DateTime value
Alternatively, you can use one of the
overloaded constructors of the
DateTime structure to assemble a date
and time value. The following example
creates a value to represent May 31,
1993 at 12:14 in the afternoon.
Dim dateInMay As New
System.DateTime(1993, 5, 31, 12, 14,
0)