SSRS expression throws #Error - any reasons? - reporting-services

I am new to the SSRS This is expression i am trying but it's showing "#Error" i tried varies things but still not any progress any guess why might it's happening.
=IIF(Fields!MailMeans.Value = "M","METER",
IIF(Fields!MailMeans.Value = "I","INDICIA",
IIF(Fields!MailMeans.Value = "S","STAMPS",
IIF(Fields!MailMeans.Value = "N","NO-MAIL","")
)
)
)

Try using Switch rather than the nested IIF
=Switch(Fields!MailMeans.Value = "M", "METER",
Fields!MailMeans.Value = "I", "INDICIA",
Fields!MailMeans.Value = "S", "STAMPS")

This should also work:
=Switch(Fields!MailMeans.Value = "M", "METER",
Fields!MailMeans.Value = "I", "INDICIA",
Fields!MailMeans.Value = "S", "STAMPS",
Fields!MailMeans.Value = "N", "NO-MAIL",
Fields!MailMeans.Value <> "M" AND Fields!MailMeans.Value <> "I" AND
Fields!MailMeans.Value <> "S" AND Fields!MailMeans.Value <> "N", "")

Related

Implement function call (grouped running totals) in query

I have a function called fxGroupedRunningTotal (fxGRT) and a query (Totals). I want to call fxGRT within Totals, so that I get a column that shows the grouped running totals. I have only managed to test the fxGRT by importing the Totals query.
Query that uses Totals and calls fxGRT (built for testing the function):
let
Source = Totals,
BufferedValues = List.Buffer(Source[PD]),
BufferedMaterials = List.Buffer(Source[Material]),
RT = Table.FromColumns(
{
Source[Material], Source[Date], Source[PD],
fxGroupedRunningTotal(BufferedValues, BufferedMaterials)
},
{
"Material",
"Date",
"PD",
"Running Total"
})
in
RT
fxGroupedRunningTotals:
(values as list, grouping as list) as list =>
let
GRTList = List.Generate
(
()=> [ GRT = values{0}, i = 0 ],
each [i] < List.Count(values),
each try if grouping{[i]} = grouping{[i] + 1}
then [GRT = [GRT] + values {[i] + 1}, i = [i] + 1]
else [GRT = values{[i] + 1}, i = [i] + 1]
otherwise [i = [i] + 1]
,
each [GRT]
)
in
GRTList
Totals:
let
Källa = Table.NestedJoin(Cohv,{"Prod MDate"},Resb,{"Del Mdate"},"Resb",JoinKind.FullOuter),
#"Expanderad Resb" = Table.ExpandTableColumn(Källa, "Resb", {"Del Material", "Del Date", "Del Qty", "Del Mdate"}, {"Del Material", "Del Date", "Del Qty", "Del Mdate"}),
#"PD Date" = Table.AddColumn(#"Expanderad Resb", "PD Date", each if [Prod Date] = null then [Del Date] else [Prod Date]),
#"PD Material" = Table.AddColumn(#"PD Date", "PD Material", each if [Material Number] = null then [Del Material] else [Material Number]),
#"PD Mdate" = Table.AddColumn(#"PD Material", "PD Mdate", each [PD Material] & "." & Date.ToText([PD Date])),
#"Borttagna kolumner" = Table.RemoveColumns(#"PD Mdate",{"Prod Date", "Prod MDate", "Del Date", "Del Mdate"}),
#"Ändrad typ1" = Table.TransformColumnTypes(#"Borttagna kolumner",{{"PD Date", type date}}),
#"Ihopslagna frågor" = Table.NestedJoin(#"Ändrad typ1",{"PD Material"},Matmas,{"Material"},"Matmas",JoinKind.FullOuter),
#"Expanderad Matmas" = Table.ExpandTableColumn(#"Ihopslagna frågor", "Matmas", {"Material", "Material Description", "MRP Controller", "Safety stock", "Minimum Lot Size", "In Stock"}, {"Material", "Material Description", "MRP Controller", "Safety stock", "Minimum Lot Size", "In Stock"}),
#"Omdöpta kolumner" = Table.RenameColumns(#"Expanderad Matmas",{{"Material", "M Material"}}),
#"Lägg till egen" = Table.AddColumn(#"Omdöpta kolumner", "Material", each if [PD Material] = null then [M Material]else [PD Material]),
#"Borttagna kolumner1" = Table.RemoveColumns(#"Lägg till egen",{"Material Number", "Del Material", "PD Material", "M Material"}),
#"Lägg till egen1" = Table.AddColumn(#"Borttagna kolumner1", "Date", each if [PD Date] = null then DateTime.LocalNow() else [PD Date]),
#"Borttagna kolumner2" = Table.RemoveColumns(#"Lägg till egen1",{"PD Date"}),
#"Lägg till egen2" = Table.AddColumn(#"Borttagna kolumner2", "Date in stock", each if [Date] = DateTime.Date(DateTime.LocalNow()) then [In Stock] else null),
#"Borttagna kolumner3" = Table.RemoveColumns(#"Lägg till egen2",{"Date in stock"}),
#"Ändrad typ" = Table.TransformColumnTypes(#"Borttagna kolumner3",{{"Date", type date}}),
#"Ersatt värde" = Table.ReplaceValue(#"Ändrad typ",null,0,Replacer.ReplaceValue,{"Prod Qty"}),
#"Ersatt värde1" = Table.ReplaceValue(#"Ersatt värde",null,0,Replacer.ReplaceValue,{"Del Qty"}),
#"Ihopslagna frågor1" = Table.NestedJoin(#"Ersatt värde1",{"Date"},Dates,{"Date"},"Dates",JoinKind.RightOuter),
#"Expanderad Dates" = Table.ExpandTableColumn(#"Ihopslagna frågor1", "Dates", {"Current Date"}, {"Current Date"}),
#"Omdöpta kolumner1" = Table.RenameColumns(#"Expanderad Dates",{{"Date", "D Date"}}),
Date = Table.AddColumn(#"Omdöpta kolumner1", "Date", each if [D Date] is null then DateTime.Date(DateTime.LocalNow()) else [D Date]),
PD = Table.AddColumn(Date, "PD", each if [Current Date] = "Yes" then [In Stock]+[Prod Qty]-[Del Qty] else [Prod Qty]-[Del Qty])
in
PD
So how do I implement this function into a new column in my Totals? My attempts keep failing. Do I have to make a reference to Totals in order to make this work? It feels so wrong, since that would double the work load (?) with the data. I would like it to be as quick as possible.
You can reference the previous step as a table. Thus your query can be written
let
[...all your previous steps...]
PD = Table.AddColumn(Date, "PD", each if [Current Date] = "Yes" then [In Stock]+[Prod Qty]-[Del Qty] else [Prod Qty]-[Del Qty]),
RT =
Table.FromColumns(
List.Combine({Table.ToColumns(PD), {fxGroupedRunningTotals(PD[Material], PD[PD])}}),
List.Combine({Table.ColumnNames(PD), {"Running Total"}})
)
in
RT
This converts the table to a list of columns, adds on the new running total column (calling the function you've defined on specific columns of the table from the previous step PD), and then glues those columns back together with a similar method to preserve the column names and add a new one.

Couchbase array index not getting used in the query

I have the following document structure:
{
"customerId": "",
"schemeId": "scheme-a",
"type": "account",
"events": [
{
"dateTime": "2019-03-14T02:23:58.573Z",
"id": "72998bbf-94a6-4031-823b-6c304707ad49",
"type": "DebitDisabled",
"authorisedId": ""
},
{
"dateTime": "2018-05-04T12:40:15.439Z",
"transactionReference": "005171-15-1054-7571-60990-20180503165536",
"id": "005171-15-1054-7571-60990-20180503165536-1",
"type": "Credit",
"authorisedId": ",
"value": 34,
"funder": "funder-a"
},
{
"dateTime": "2019-03-06T04:14:54.564Z",
"transactionReference": "000000922331",
"eventDescription": {
"language": "en-gb",
"text": "
},
"id": "000000922331",
"type": "Credit",
"authorisedId": "",
"value": 16,
"funder": "funder-b"
},
{
"dateTime": "2019-03-10T04:24:17.903Z",
"transactionReference": "000001510154",
"eventDescription": {
"language": "en-gb",
"text": ""
},
"id": "000001510154",
"type": "Credit",
"authorisedId": "",
"value": 10,
"funder": "funder-c"
}
]
}
And the following indexes :
CREATE INDEX `scheme-a_customers_index`
ON `default`(`type`,`schemeId`,`customerId`)
WHERE ((`schemeId` = "scheme-a") and (`type` = "account"))
WITH { "num_replica":1 }
CREATE INDEX `scheme-a_credits_index`
ON `default`(
`type`,
`schemeId`,
`customerId`,
(distinct (array (`e`.`funder`) for `e` in `events` when ((`e`.`type`) = "Credit") end))
)
WHERE ((`type` = "scheme") and (`schemeId` = "scheme-a"))
WITH { "num_replica":1 }
I am trying to query all the customerIds and events for each where type="credit" and funder like "funder%"
below is my query :
SELECT
customerId,
(ARRAY v.`value` FOR v IN p.events WHEN v.type = "Credit" AND v.funder like "funder%" END) AS credits
FROM default AS p
WHERE p.type = "account" AND p.schemeId = "scheme-a"
AND (ANY e IN p.events SATISFIES e.funder = "funder-a" END)
I am expecting the query to use the index scheme-a_credits_index, instead it is using scheme-a_customers_index. Can't understand why ! isn't the query supposed to use scheme-a_credits_index ?
Your query doesn't have predicate on customerId. So query can only push two predicates to indexers and both indexes are qualify. scheme-a_customers_index is more efficient because of number of entries in the index due to non array index.
You should try the following.
CREATE INDEX `ix1` ON `default`
(DISTINCT ARRAY e.funder FOR e IN events WHEN e.type = "Credit" END, `customerId`)
WHERE ((`schemeId` = "scheme-a") and (`type` = "account")) ;
SELECT
customerId,
(ARRAY v.`value` FOR v IN p.events WHEN v.type = "Credit" AND v.funder like "funder%" END) AS credits
FROM default AS p
WHERE p.type = "account" AND p.schemeId = "scheme-a"
AND (ANY e IN p.events SATISFIES e.funder LIKE "funder%" AND e.type = "Credit" END);

Converting * character in SSRS Expression

I am using the following expression in SSRS
=IIF(ReportItems!Textbox69.Value = "~*",
"Excellent", IIF (ReportItems!Textbox69.Value = 1,
"Very Good", IIF (ReportItems!Textbox69.Value = 2,
"Good", IIF (ReportItems!Textbox69.Value = 3,
"Modest", "Cause for Concern")
)
)
)
When I run my report, all the fields that had a * originally are coming up as an error. How can I convert this character please?
Since your textbox contains strings you have to use quotes in comparisons
=IIF(ReportItems!Textbox69.Value = "*",
"Excellent", IIF (ReportItems!Textbox69.Value = "1",
"Very Good", IIF (ReportItems!Textbox69.Value = "2",
"Good", IIF (ReportItems!Textbox69.Value = "3",
"Modest", "Cause for Concern")
)
)
)
I would also suggest to consider using Switch instead of nested Iif
= Switch(
ReportItems!Textbox69.Value = "*", "Excellent",
ReportItems!Textbox69.Value = "1", "Very Good",
ReportItems!Textbox69.Value = "2", "Good",
ReportItems!Textbox69.Value = "3", "Modest",
True,"Cause for Concern"
)

Sum of a nested iif statement

I have the following nested iif statement that brings back an error "End of Statement expected."
Can someone please help? I know its probably very straightforward but i have been looking at this for sometime.
Thanks
=SUM(IIF(Fields!Grade.Value = "A*", 6, IIF(Fields!Grade.Value = "A", 5, IIF(Fields!Grade.Value = "B", 4, IIF(Fields!Grade.Value = "C" , 3, IIF(Fields!Grade.Value = "D" , 2 , IIF(Fields!Grade.Value = "E", 1, IIF(Fields!Grade.Value = "E/U", 0))))))) - IIF(Fields!Target_Grade.Value = "A*" , 6, IIF(Fields!Target_Grade.Value = "A", 5, IIF(Fields!Target_Grade.Value = "B", 4 , IIF(Fields!Target_Grade.Value = "C", 3, IIF(Fields!Target_Grade.Value = "D", 2, IIF(Fields!Target_Grade.Value = "E" , 1, IIF(Fields!Target_Grade.Value = "U", 0)))))))))
I needed an else 0 statement, added this to the code to give the below and all is good
=SUM(IIF(Fields!Grade.Value = "A*", 6, IIF(Fields!Grade.Value = "A", 5, IIF(Fields!Grade.Value = "B", 4, IIF(Fields!Grade.Value = "C" , 3, IIF(Fields!Grade.Value = "D" , 2 , IIF(Fields!Grade.Value = "E", 1, IIF(Fields!Grade.Value = "E/U", 0, 0))))))) - IIF(Fields!Target_Grade.Value = "A*" , 6, IIF(Fields!Target_Grade.Value = "A", 5, IIF(Fields!Target_Grade.Value = "B", 4 , IIF(Fields!Target_Grade.Value = "C", 3, IIF(Fields!Target_Grade.Value = "D", 2, IIF(Fields!Target_Grade.Value = "E" , 1, IIF(Fields!Target_Grade.Value = "U", 0, 0))))))))
I think you have one too many closing brackets- you could try removing the last bracket.
(I pasted your code into Notepad++ and put in a carriage return for each opening bracket and closing bracket. Notepad++ highlights the matching opening and closing brackets, and there was one left over))

MySql case statement error

When I use this code in a create view construct it returns empty result set.
I have tried using a column name after the case and removing the column name in the when lines...no change... any ideas. I have determined the issue is at the case statement by commenting it out and running it and it works fine then....
CREATE or REPLACE VIEW orderMSTRview
AS
SELECT SB.name "Brand", O.orderID "Order ID", O.orderRecID "Record ID", O.orderDate "Date Created",
O.salesRepName "Sales Rep Name", O.salesRepEmail "Sales Rep Email",
O.orderNumer "Order Number", O.orderType "Order Type",
CASE
when fulfillStatus = 0 then 'open'
when fulfillStatus = 1 then 'processing'
when fulfillStatus = 2 then 'complete'
when fulfillStatus = 5 then 'Shipped'
when fulfillStatus = 9 then 'void'
END as "Order Status" ,
IF(O.payStatus=0,'unpaid','paid') "Payment Status",
O.totalOrderQuantity "Total Order Quantity",
O.subtotalOrderValue "Subtotal Order Value",
O.totalOrderValue "Total Order Value", O.credit "Order Credit",
O.taxAmount "Tax Amount", O.shippingCost "Shipping Cost",
O.finalInvoiceValue "Invoice Amount", O.currency "Currency",
O.shipDate "Ship Date", O.cancelAfter "Cancel Date", O.terms "Terms",
O.buyerName "Buyer Name", O.buyerEmail "Buyer Email", O.buyerPhone "Buyer Phone", O.custCode1 "Customer Code1", O.custCode2 "Customer Code2",
O.custERP "Customer ERP", O.customerPO "Customer PO", O.custVat "VAT number",
O.billToName "Bill To Name", O.billToStreet1 "Bill To Address1" ,
O.billToStreet2 "Bill To Address2", O.billToCity "Bill To City",
O.billToState "Bill To State", O.billToZip "Bill To Zip code",
O.shipToName "Ship To Name", O.shipToStreet1 "Ship To Address1",
O.shipToStreet2 "Ship To Address2",
O.shipToCity "Ship To City", O.shipToState "Ship To State",
O.shipToZip "Ship To Zip code",
O.tagname1 "Tag 1", O.tagname2 "Tag 2", O.tagname3 "Tag 3"
FROM orders as O left join showroom_brand as SB on O.showroomID = SB.sid
WHERE O.orderDate >= '2015-01-01' and SB.name IS NOT NULL;
Do it like this example:
try to run this
set #fulfillStatus = 1;
select
CASE
when #fulfillStatus = 0 then 'open'
when #fulfillStatus = 1 then 'processing'
when #fulfillStatus = 2 then 'complete'
when #fulfillStatus = 5 then 'Shipped'
when #fulfillStatus = 9 then 'void'
else "None"
END as "Order Status"