Case Statement Assistance - sql

I have a case statement currently built but need to add an extra layer and I'm not sure of the most efficient and accurate way of doing it. I have these drug codes that are for SYRINGE usage, and another set of codes for PEN usage. I have those layers built in, easy enough. I am trying to add a third layer to determine if the member used both a pen and a syringe, so the member would have a code from both categories during my specified time period. Any ideas? Thanks in advance for the help!
, CASE WHEN NDC.GPI IN (
'2710400300D220',
'2710400300D233',
'2710400300D236',
'2710400400D220',
'2799100225D220',
'2799100235D220') THEN 'PEN'
WHEN NDC.GPI IN (
'27104004002022',
'27104010002005',
'27104020001805',
'27104070001820',
'2730001000E530') THEN 'SYRINGE'
ELSE 'OTHER' END AS DOSAGE_FORM

Related

SAP BODS DI_OPERATION TYPE = 'X'

Hope you are doing good. We are having an issue where the DI_OPERATION_TYPE = 'X'. As I have aware that possible values would be I,D,B and U.
Case 1:
This is happing in some Initial full loads. Example Customer Attributes etc.
Case 2:
Also happening in some delta extracts. Example. GL Entries Balance.
What could be the cause of it?
Thanks in advance.

New to Python and Pandas, Looking for help aggregating observations

I am relatively new to using Python and Pandas, and was looking for help with this line of code:
`Football.ydstogo[Football.ydstogo>='11']&[Football.ydstogo<='19']= '10-plus`'
I am working with data from the NFL, and trying to build a model to predict when a team will pass, or when a team will run the ball. One of my variables (ydstogo) measures the distance for the team, with the ball, to get a first down. I am trying to group together the observations after 10 yards for ease of visualization.
When I tried running the code above, the error in my output is "can't assign to operator". I've used this code before to change gender observations to dummy variables, so I'm confused why it is not working here.
As I understand, you want to find elements with (string)
value between '11' and '19' and set a new string there.
So probably your should change your code to:
Football.ydstogo[(Football.ydstogo >= '11') & (Football.ydstogo <= '19')] = '10-plus'
Alternative:
Football.ydstogo[Football.ydstogo.between('11', '19')] = '10-plus'

basic mdx question using Ms Excel OLAP tools

I will make this question and scenario as basic as possible since I have no background on programming. How do I make a script where all red will be multiplied by 5, yellow by 6 and blue by 7? The new measure will aggregate in grand total. I don't know what expressions to use. Just use [Product] for the colors and [Measure] for qty.
enter image description here
I dont understand yet the use of MEMBERS and other expressions as this is my first time to be on it. I tried
([Measure].[Quantity],[Product].&[Yellow])*6
but it will just multiply everything with 6. Maybe FILTERS? IIF? I just don't know how. The script will go a long way when I will apply it in our database. thanks!
I know you asked about doing this with excel, but if you were writing an MDX query you could do create a new measure and run the query like this:
WITH
member measures.[ColorQuantity] AS CASE WHEN [Product].[Product].currentmember.member_key = "Yellow" THEN measures.[Quantity] * 6
WHEN [Product].[Product].currentmember.member_key = "Blue" THEN measures.[Quantity] * 5
WHEN [Product].[Product].currentmember.member_key = "Red" THEN measures.[Quantity] * 2
ELSE measures.[Quantity] END
SELECT {
measures.[Quantity], measures.[ColorQuantity]
} ON 0,
Non EMPTY
{
[Product].[Product].[All].Children /// I dont know the FULL dimension AND hierarchy path you want TO use
} ON 1
FROM YourCubeName
This might help you get started.

How to sum data by in a category in Spotfire

What would the custom expression be to sum data by a category, for each site.
Using the data below, I would like to Sum[X] for only values with category blue, for each site
What I have so far is Sum([X]) OVER [Site] --> Where / how do I put in the category qualifier?
the Intersect() function is a perfect fit here. it creates a hierarchy based on however many columns you list. more info in the documentation.
anyway, try the following:
Sum([X]) OVER (Intersect([Site], [Category]))
To do the same for only a single category, you can use an expression like
Sum(If([Category]="Blue",[X],0)) OVER ([Site])
This will leave a null/empty value when [X] is not "Blue" (case sensitive so beware!).
If you have multiple values, you can replace the condition with
If([X] in ("Blue", "Nurple", "Taupe"), ...)
what I found works best is: Sum(If([Category]="Blue",[X],0)) OVER ([Site])

SSRS 2008 R2 returns "#ERROR" when exporting to PDF

I am attempting to parse a string that contains a device's make, model, and serial number into separate fields to end up in their own column in the report.
The source value would generally be something like 3B0645X01543 APCBack-UPS ES 550 FW:840.B2.D USB FW:B2 where the first set of characters is the serial number, APC is the make, and Back-UPS ES 550 is the model. My goal is to have my report return a value of "APC" for make, the number value after ES for model, and the first character set for serial number. I have this working as long as I render directly to HTML. If I render to PDF, Excel, or anything else each of these columns return #Error. Here is how I'm doing it.
The source is a field in the same data set named DeviceID. For the example, it contains the string 3B0645X01543 APCBack-UPS ES 550 FW:840.B2.D USB FW:B2.
I have 3 calculated fields in my dataset, Make, Model, and Serial. The expression for Make is below.
=SWITCH(Fields!DeviceID.Value.ToString().Contains("EATON"), "Eaton", Fields!DeviceID.Value.ToString().Contains("APC"), "APC", Fields!DeviceID.Value.ToString().Contains("Tripp"), "TrippLite", Fields!DeviceID.Value.ToString().Contains("American"), "APC")
I am then using a lookup function to pull this Make field into the table in my report.
Again, if I render to HTML all three values work like a champ. Any other render gets me #Error.
Any help is GREATLY appreciated!
I tried to replicate this with the version I have available (SQL 2012) but I could not reproduce the issue. A bit of research on Google showed this same issue has occurred for others and seems to be related to using the Lookup function in some situations, but I did not find a solution.
However I can suggest a workaround to try:
Instead of adding calculated fields to your dataset, add some custom code to the report to parse the DeviceID. For example to get the Make, you could use something like this (apologies there is probably a much more elegant way of doing this):
Public Function DeviceIDMake(ByVal DeviceID As String) As String
If DeviceID.ToString().Contains("EATON") Then
Return "Eaton"
Else
If DeviceID.ToString().Contains("APC") Then
Return "APC"
Else
If DeviceID.ToString().Contains("Tripp") Then
Return "TrippLite"
Else
If DeviceID.ToString().Contains("American") Then
Return "APC"
Else
Return ""
End If
End If
End If
End If
End Function
Then in your report, you can call the code like so to get the "Make":
=Code.DeviceIDMake(Fields!DeviceID.Value)
This might avoid whatever is causing your rendering issue.