SSAS/SSRS : no percentage format? - reporting-services

I want to format a percentage in SSAS and SSRs but both fail.
In SSAS the value I want to format is a named calculation :
, but the format isn't applied.
According to this post in SO, there was a regression in visual studio (SSDT).
In SSRS, the following MDX request:
with member [Measures].Pct as [Measures].[Pourcentage Patients par hôpital et âge], FORMAT_STRING="Percent"
SELECT {[Measures].[VPARCOURS Nombre], [Measures].[Pct] } ON 0,
{ strtoset(#Hospital) * { [Dim Age].[catage1].[Cat Age1] - [Dim Age].[catage1].[All].UNKNOWNMEMBER
} } ON 1
FROM [BDD PBM]
gives the expected result but not formatted (e.g. 6.89544172413793).
Is there a way to get, in the cube or in the reports, the value in a format like "6.90%"?

My first thought would be to not format the value in SSAS and just return the value 0.0689544172413793
You could then set the textbox format property in SSRS to p2 to give display as a percentage.

Related

SSRS Report Shows #Error When Converting Number to Currency

I am trying to get the report to show the purchase price which the user enters in a parameter. If the user doesn't enter anything it will say "Undisclosed" otherwise I want it to show the purchase price as currency. I have tried the following:
=IIF(Parameters!PurchasePrice.Value = "", "Undisclosed", Cstr(Format(Parameters!PurchasePrice.Value, "C")))
=IIF(Parameters!PurchasePrice.Value = "", "Undisclosed", Format(Parameters!PurchasePrice.Value, "C"))
=IIF(Parameters!PurchasePrice.Value = "", "Undiscloded", FormatCurrency(Parameters!PurchasePrice.Value,0))
=IIF(Parameters!PurchasePrice.Value = "", "Undiscloded", FormatNumber(Parameters!PurchasePrice.Value,0))
I can get "Undisclosed" to appear but every time I enter a number it shows #Error
You can try the following solution:
=IIF(IsNumeric(Parameters!PurchasePrice.Value), Format(Val(Parameters!PurchasePrice.Value), "C"), "Undisclosed")
I would approach this slightly differently. This will avoid SSRS trying to format a non numeric to a currency. IIF will evaluate both the true and false outcomes even though only one result can be true for each instance.
I would set the textbox that shows the purchase price up as follow...
Set the Value expression to be
=VAL(Parameters!PurchasePrice.Value)
This will return a zero if the parameter value is left as blank/empty string
Then set the Format property of the textbox to
$#.00;-$#.00;Undisclosed
Assuming you want $ as the currency symbol. This format string will format the number to two decimals for positive and negative numbers and prefix the $ symbol but for zero values, it will show the work "Undisclosed"

Do not show JSON data in columns

The software I'm using saves a copy of the data that I think is json in an extra-different table when I do records in the database.
What I want to do is to be able to query the json data contained in the DATASETS column separately.
I'm using SQL 2012 as my server
This is the query I tried so far:
SELECT TOP 1 IND, SNAPSHOTDATE, DATASETS, USERNAME, OWNERFORM
FROM TBLSNAPSHOTS
CODE RESULT:
105 2018-09-14 02:59:34.000 { "Datasets": [{"Name": "TBLSTOKLAR","Lines": [{"IND": "102","STOKNO": "","MALINCINSI": "TITIZ PLASTIK BUYUK KASIK 10 ADET","STOKKODU": "8691262708050","ANABIRIM": "102","BIRIMEX": "102","ALTSEVIYE": "","KRITIKSEVIYE": "","USTSEVIYE": "","DEPOSEVIYESI": "True","URETICI": "","AYLIKVADE": "0","SERINO": "","DEPO": "1","STOKGRUBU": "","GARANTI": "0","PRIM": "0","IPTAL": "False","STOKTIPI": "0","STOKTAKIP": "0","TEMINYERI": "1","RAFOMRU": "0","RESIM": "","KALAN": "0","REZERV": "0","KOD1": "","KOD2": "","KOD3": "","KOD4": "","KOD5": "","KOD6": "","KOD7": "","KOD8": "","KOD9": "","KOD10": "","TAKSITSAYISI": "0","ISTIHBARAT": "","FIYATYOK": "","DELETED": "","ALISFIYATI": "0","ESKIALISFIYATI": "0","SONALISTARIHI": "","SONSATISTARIHI": "","KARTINACILMATARIHI": "14.09.18 ı. 02:57:58","DEVIRIND": "","MALIYET": "1","KDVGRUBU": "1","AKTIF": "False","ISCILIKIND": "0","ISCILIKBIRIMIND": "0","ISCILIKACIKLAMA": "","ISCILIKSTOKKODU": "","ALISFIYATIDEGISMETARIHI": "","STATUS": "1","DALISFIYATI": "","APB": "","OIV": "0","KARORANI": "0","OTV": "0","ISK": "0","STOKGRUPTANIMI": "","ISKSATISFIYATI2": "0","ISKSATISFIYATI3": "0","ALISKDVORANI": "18","ALISISKORANI": "","SIPARISALINMASIN": "False","SIPARISVERILMESIN": "False","P1": "","P2": "","P3": "","SATISKOSULU": "","DEFAULTALISFIYATI": "","DEFAULTALISFIYATIDEGISMESTARIHI": "","KDVGRUBUT": "","HEDEFSATISFIAYTI": "","KURUMISKONTOSU": "","TICARIISKONTO": "","ITSBILDIRIMI": "False","MAXISKORANI": "","IMALATCISATISFIYATI": "","DKUR": "1","ACILSEVK": "False","SOGUKSEVK": "False","ICMIKTAR": "","TICARISEKIL": "","MAXISKTUTAR": "","TAXE": "","KOD11": "","DAPB": "","IKINCIEL": "","ETICARET": "","STOKNEVI": "0","OTVORANSAL": "True","POZ": "","YAZARKASA": "False","KOD12": "","KOD13": "","KOD14": "","KOD15": "","KOD16": "","KOD17": "","KOD18": "","KOD19": "","KOD20": "","KOD21": "","UID": "{0DE71D73-E447-45B0-BF6A-1D312DBAFDD2}"}]}]} ADMIN frmEdtStok```
In SQL 2012 - no, you can't directly query the JSON. In SQL 2016 they added functions to let you do this:
https://learn.microsoft.com/en-us/sql/t-sql/functions/json-query-transact-sql?view=sql-server-2017
But if you need to stay on 2012 you are limited to String parsing it (don't do this), or writing/finding a CLR function which parses it using .Net code and returns the results
If you simply must do it quickly there are some hackey solutions to parse it like so: https://www.red-gate.com/simple-talk/sql/t-sql-programming/consuming-json-strings-in-sql-server/ but don't expect it to work smoothly with complex json

SSRS REPORT BUILDER, Comparing two diffrent data sets in one Tablix, Expression

I have two datasets and want to compare them in an expression.
I would like to do something like this:
=iif(Fields!Grade.Value = "ONGRADE" > LookupSet(Fields!Grade.Value = "ONGRADE", Fields!grade.Value = "ONGRADE" , Fields!grade.Value = "ONGRADE", "Previous3Week"), "UP" ,"DOWN")
This currently returns "Error" within the "ONGRADE" row.
you need to bind your component with one of the datasets and then accordingly you can write following expression :
=iif(Fields!grade.Value > (Fields!grade.Value, "ONGRADE_DataSet2") , "UP", "DOWN")
in this example, the component is binded with the first dataset and the second dataset is getting referred.
This may help.

SSRS Filter by parameter and Value condition

I am trying to add an parameter that will allow the user to filter by unit Cost. I.e. If for parameter Unit cost, User select "All Costs", it will not perform any filter and will show all items. However, if for the parameter Unit cost, the user selects "Greater than 0" it would only display items that have unit cost > 0.
I have declared the parameter with two available values "U" and A".
However, what would the Parameter condition look like? I tried adding the condition which was =IIF(Parameter!Text.Value = "U", UnitCost, NOTHING) > 0.
This doesn't seem to be working though. Can anyone provide suggestions as to how this would be done.
You can use an expression to determine if a row should be filtered or not based on the parameter selected value.
Add a new Filter condition in your tablix and use these settings and expressions:
In Expression textbox use:
=Switch(
Parameters!Text.Value = "All", "Include",
Parameters!Text.Value = "U" AND Fields!UnitCost.Value > 0, "Include",
Parameters!Text.Value = "A" AND Fields!UnitCost.Value > 10, "Include",
true, "Exclude"
)
In the Value textbox use:
="Include"
Note your parameter should have an available value as conditions to filter you need.
In this case I use A parameter value to filter the UnitCost values greater than 10 and U value to filter UnitCost values greater than 0. Customize to meet your requeriment.
Let me know if this helps.

Hide row based on a value from another dataset

I have a tablix that has one dataset, and I need to hide one row based on a value in another dataset.
Currently I have this expression under visibility:
=Iif(Fields!Data1.Value="0" or Fields!Data2.Value="1", TRUE, FALSE)
Both of these are in another dataset called vDataset3.
Use this code
=IIF(First(Fields!UserID.Value, "DataSet2") = 0 or
First(Fields!UserID.Value, "DataSet2") = 12, True, False)
In order to call a field in another dataset you need to write:
First(Fields!UserID.Value, "DataSet2")
The first means that you take the first row. you have to do that because a dataset is like an array you must declare the field you would like to get.
and the "DataSet2" is the name of the dataset