Trying to generate an expression from a table based on table values - expression

My SSRS report creates a summarized table. I need to do a calculation based on 2 pieces of data from the table and add it as an expression at the bottom of the report. My expression errors out as it is not reading the data output from the table.
I have followed up on all examples I could find with the error I get, but found no resolution. I am new to SSRS. I have tested the expression by simply using the IIf statement to return the values I'm looking for (without the rest of the calculations I need) and it doesn't return either value. I get "#Error" as the result. I have copied the lookup values directly from the SQL code, so I KNOW there are no typos in my comparison values.
I have this for the code in my expression:
=Code.Divide
(IIf(Fields!Results.Value = "BKR3 - Total Overtime Hours", Fields!Results.Value, 0)) ,
(IIf(Fields!Emp_Type.Value = "BKR1 - Total Paid Hours", Fields!Results.Value, 1))
Through another stackoverflow question I found this code and have added it to my report:
Public Function Divide(ByVal dividend as Double, ByVal divisor as Double) As Double
If IsNothing(divisor) Or divisor = 0 Or IsNothing(dividend) Or dividend=0 THEN
Return 0
Else
Return dividend/divisor
End If
End Function
I am getting this error:
The Value expression for the textrun
‘Textbox3.Paragraphs[0].TextRuns[0]’ contains an error: [BC30455]
Argument not specified for parameter 'divisor' of 'Public Function
Divide(dividend As Double, divisor As Double) As Double'.
This is what my output looks like:
*Emp_Type Results
*A3-Facility Payroll Hours 28,252.20
*A4-Provider Payroll Hours 1,998.50
*BKR1-Total Paid Hours 30,250.70
*BKR2-Total Worked Hours 27,037.62
*BKR3-Total Overtime Hours 504.20
*BS1-Hospital FTEs 99.72
*BS2-Clinic FTEs 23.25
Overtime % #Error
(I'm very sorry, I cannot get the list to indent!)
I am expecting this as my results:
Overtime % 0.18%
This is what I am getting instead:
Overtime % #Error

Related

Relational Algebra: Problems with division operator

I am writing a query, where I am using the division operator. For some reason I can't get it to work properly, and I can't see why.
pol = pi allergen (sigma allergy_type = 'pollen' (allergies))
tmp = (patient_allergies/pol)
tmp
The above is my query. In pol I am retrieving all allergens, who has the allergy type pollen. This gives me a 1 column, two rows table, which content is the two allergens who has allergy_type pollen.
tmp:
Patient_allergies is a 2 column, 23 row table. The first column is allergens, second column is ssn for the people with those allergens.
What I am trying to do, is to get everyone in patient_allergies, who has the two allergens I found in pol. I'm pretty sure I need to division operator for this, but it returns an empty list, which is incorrect for what I am trying to do.
EDIT: I am using this relational algebra calc, provided by our university: dbis-uibk.github.io/relax/calc/local/uibk/local/0 There is a division operator with another symbol, but yields the same result

If Statement error: Expressions that yield variant data-type cannot be used to define calculated columns

I'm new in Power BI and I'm more used to work with Excel. I try to translate following Excel formula:
=IF(A2="UPL";0;IF(MID(D2;FIND("OTP";D2)+3;1)=" ";"1";(MID(D2;FIND("OTP";D2)+3;1))))
in Power Bi as follows:
Algo =
VAR FindIT = FIND("OTP",Fixed_onTop_Data[Delivery Date],1,0)
RETURN
IF(Fixed_onTop_Data[Delivery Type] = "UPL", 0,
IF(FindIT = BLANK(), 1, MID(Fixed_onTop_Data[Delivery Date],FindIT+3,1))
)
Unfortunately I receive following error message:
Expressions that yield variant data-type cannot be used to define calculated columns.
My values are as follows:
Thank you so much for your help!
You cant mix Two datatypes in your output; In one part of if, you return an INT (literally 0/1), and is second you return a STRING
MID(Fixed_onTop_Data[Delivery Date],FindIT+3,1)
You must unify your output datatype -> everything to string or everything to INT
Your code must be returning BLANK in some cells therefore PowerBI isn't able to choose a data type for the column, wrap your code inside CONVERT(,INTEGER).

SPSS Count function advice

Im having some issues with some SPSS code. Im new to SPSS and still trying to figure out the syntax. I'm trying to get my code to count the sum of two dice equal to 7. I cant get the count function to work the way I want it. Below is my code. Any tips would be greatly appreciated.
INPUT PROGRAM.
LOOP #I=1 TO 100000.
COMPUTE case = 1.
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
EXECUTE.
COMPUTE Dice_1 = TRUNC (RV.UNIFORM(1,7)).
COMPUTE Dice_2 = TRUNC (RV.UNIFORM(1,7)).
COMPUTE total = Dice_1+Dice_2.
COMPUTE Number_Sum7= Dice_1+Dice_2 = 7.
COUNT Num= case TO Number_Sum7(1).
SAVE outfile = 'my file path'.
count function counts across a list of variables, in each line separately.
What you seem to be looking for is to count over rows.
You can start with:
frequencies total. /* see counts of all possible totals.
means Number_Sum7/cells=sum. /* count only the cases where total=7.
These will give you the answers in the output window.
If you want the answers in data for further analysis, look up the aggregate function.
For example, the following will give you the same results but in a new datasets:
DATASET NAME ORIG.
DATASET DECLARE freqs.
AGGREGATE /OUTFILE='freqs' /BREAK=total /Mycount=N.
DATASET ACTIVATE ORIG.
DATASET DECLARE only7.
AGGREGATE /OUTFILE='only7' /BREAK= /only7=sum(Number_Sum7).
Or, instead, you can add the results to your present data:
AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK=total /TotalCount=N.
AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK= /total7=sum(Number_Sum7).

Mismtach Error in Foxpro SQL insertion

I need someone could help me out on how to trace the error of "mismatched data type" in visual foxpro 6.0 When I issues a command like this "insert into tmpcur from memvar".
tmpcur is a cursor having bulk numbers of columns and it is ready hard to trace which one is having mismatch in data type for insertion problem.
It is pretty difficult to trace the insertion loop of each record into VFP tables one by one unliked MSSQL profiler.
Appreciate to someone could help. Thanks.
This should help you. I have a temp cursor created with some bogus field / column names testing for types of character, integer, double, currency, date and time. Trying to follow what is the result of your scenario, I am taking the memory variable of "bbbb" which should be double (or numeric at the least), and changed it to a string.
I am then HOLDING the error trapping routine that MAY be in effect, then setting my own (as I don't think try/catch existed in VFP6.. it may, but I just don't remember. So, I did an ON ERROR, set a variable to true. Then, I default it to false, try the insert, then check the flag. If the flag IS set, then I go into a loop and try for each column in the given table/alias (in my example it is "C_Tmp", so replace with your table/alias). It goes through each variable, and if the data type is different from the table structure, it will dump the column name and table / memory value for you to review.
You could put this to a log file or something.
Now, another consideration. Some types are completely valid and common for implied conversion, such as character and memo fields can both get strings. Integer, double, float, currency can all work with generic "numeric" values.
So, if you encounter these differences, then we can go one level further and look for comparable types, but let me know and we can adjust as needed.
At least this should give you a huge jump to your insert issue.
CREATE CURSOR C_tmp ( cccc c(10), iiii i, bbbb b(2), ccyyyy y, ddd d, tttt t )
SCATTER MEMVAR memo
m.bbbb = "wrong data type, was double with 2 decimal"
lcHoldError = ON("ERROR")
ON ERROR lFailInsert = .t.
lFailInsert = .f.
INSERT INTO C_Tmp FROM memvar
IF lFailInsert
FOR lnI = 1 TO FCOUNT( "C_Tmp" )
lcTmp = FIELD( lnI, "C_Tmp" )
IF NOT TYPE( "C_Tmp." + lcTmp ) == TYPE( "m.&lcTmp" )
? "Invalid " + lcTmp + ", C_Tmp.&lcTmp, m.&lcTmp
ENDIF
ENDFOR
ENDIF
ON ERROR &lcHoldError

Subtracting Expressions (Report Builder 3.0)

I have 2 expressions to fill in the column for the current amount and prior amount:
Current Amount: =IIf(Fields!ACCOUNTING_PERIOD.Value = Parameters!AP.Value, Fields!DEPR.Value, "")
Prior Amount: =IIf(Fields!ACCOUNTING_PERIOD.Value = Parameters!PRAP.Value, Fields!DEPR.Value, "")
What I need to is complete a 3rd column (called "Diff) by subtracting the value in the prior amount field from the value in the current amount field.
I tried to use the following expression that subtracts 1 from the other to get the difference:
=(=IIf(Fields!ACCOUNTING_PERIOD.Value = Parameters!AP.Value, Fields!DEPR.Value, 0)) – (=IIf(Fields!ACCOUNTING_PERIOD.Value = Parameters!PRAP.Value, Fields!DEPR.Value, 0))
However, I get the following errorm message:
The Value expression for the textrun ‘Textbox6.Paragraphs[0].TextRuns[0]’ contains an error: [BC30037] Character is not valid.
FYI, Textbox6 is the cells where this expression resides. Any help in correcting this expression would be greatly appreciated. Thanks for your help.
I think there are two Problems with your diff expression.
First i would take away some equal signs:
=IIf(Fields!ACCOUNTING_PERIOD.Value = Parameters!AP.Value, Fields!DEPR.Value, 0) – IIf(Fields!ACCOUNTING_PERIOD.Value = Parameters!PRAP.Value, Fields!DEPR.Value, 0)
The second thing is, that according to the error message your Fields seem to formatted as characters not doubles. So you will need to convert them before substracting them. You should already do this in your sql-code with:
CONVERT(Fields!DEPR.Value AS numeric)
Hope this helps

Resources