Set analysis formula in table does not work properly - qlikview

I have a table with formulas using set analysis syntax. Like so:
((RAWP_PRICE-ONLY({1<RAWP_YEARMONTH='$(Auswahlperiode)'}>}RAWP_PRICE))*ARRO_AnteilROAR_in_%/100)
/Sum({$<ARRO_PREISPERIODE={'$(Auswahlperiode)'}>}ARRO_ArtikelRohstoffPreis_MONTH)
My problem is now, that without the 1 inside the only expression, my table will show now results just "-" signs. But with the 1, my selcetion does not play a role anymore. But this is important.
How can get this formula running without having my selection ignored. Thanks a lot.
BTW: $(Auswahlperiode) is a variable given in a inputbox.

if you want to use 1 and still not having selections ignored, depends on how many fields you have, you can use explicit selections inside the set analysis:
for example if I want not to ignore the "Month" field then in the set analysis I will add Month=$::Month - so even though I'm using 1, Month field is not ignored.

Related

SSRS Parameter That Queries ALL When NULL and Can Query on MULTIPLE Values Without Options Listed

I have a business requirement that requires a user to be able to search for many different order numbers and be presented with additional information through my report. Since we have a very large amount of orders on any given day, I want them to be able to copy and paste the list into the SSRS Parameter (which I have setup fine now). I also want them to be able to run the report 'wide open' and have them be able to leave the parameter blank and return all orders.
I have achieved this in the past while using 'Available Values' for the parameter. But, now that I am doing it manually, I am coming across a lot of pesky errors.
I believe I am close.. I have the following simplified query:
SELECT
AssignmentNumber,
OrderNumber
FROM
tables.Activity
WHERE
((OrderNumber in (#P_ORDER_NUMBER)) or (#P_ORDER_NUMBER = ''))
When I run this, I have success in 2 of 3 scenerios
When #P_ORDER_NUMBER is left empty, it returns all orders
When a SINGLE order is provided, it returns assignments on that order
The final issue is getting it to work with multiple Orders. I am getting an Error in SSRS reading 'An Expression of Non-Boolean type specified in a context where a condition is expected, near ','.
I assume there's in issue in the OR clause that I have.. but I haven't been able to find a workaround that meets the business need. Any ideas? Thank you!!
The following is not perfect, as it won't work if some orders are selected and then the report is re-run with no orders selected but is might be OK for your needs...
Add a new parameter to the report, I called it pBlank in my tests. You can set this to hidden once the report is complete. In the default value I used the following expression.
=IIF(LEN(Parameters!P_ORDER_NUMBER.Value(0)) = 0, 1, 0)
So it will be 1 if the order parameter is empty or 0 of it is not empty. It does this by checking the length of the first value. This is assuming the user does not have add a blank value as the first value, if they do then you could do something similar by checking the .Count property too.
Then just change the dataset query to something like
SELECT
AssignmentNumber,
OrderNumber
FROM tables.Activity
WHERE (
OrderNumber in (#P_ORDER_NUMBER)
OR #pBlank = 1
)
It may just be hung up on the empty string concept. Try allowing the parameter to be NULL - the user will get a little checkbox that says "null" - and for the parameter prompt say
Enter order number(s) or check "null" for all:
Change your query to ...or (#P_ORDER_NUMBER IS NULL)
This has always worked for me. HTH

Is there a way to use variables in vba to identify MS-Access report fields?

I am not a programmer, but have been tasked with doing this anyway! We are working on a research project that involves testing properties of different samples. I am trying to create a form that will generate a custom report based on what the user chooses. So, I have multiple text boxes and check boxes to allow the user to define the query parameters (e.g. composition of the sample must contain at least 5% component A) and choose what data they are interested in seeing in said report (e.g. show pH, color, but not melting point). I have successfully created code to generate the query, then generate a report based on that query, but the report defaults to column widths that are generally too big (for example, the pH column width is 3 inches, it only needs to be about 1). I would like to be able to fix this, but have not been able to figure out how. At the same time, some of these fields contain numbers that are averages of multiple test results, so I would like to limit the number of digits shown, and display them as % where appropriate. I started with just fixing the column width issue:
I have tried to make a collection of the fields that are included, then loop through the collection and set column widths, but cannot figure out how to identify a field with a variable:
If I know the field name I can do this:
Reports("ReportName")!FieldID.Width = 200
But if I have a collection of names, FieldNames, or a string VariableName, none of these work, giving me an error that FieldNames or VariableName is not a valid field in the report:
Reports("ReportName")!FieldNames(1).Width = 200
Reports("ReportName")![FieldNames(1)].Width = 200
Reports("ReportName")![VariableName].Width = 200
Is there a way to reference a field name with a variable?
Alternatively, I thought there might be a way to loop through all fields and set widths - this would involve looking up a column width for each field, which I thought to do by adding a key to a collection of column widths. But I cannot find a way to do that, something like:
For each Field in Reports("Report")
Field.Width = ColumnWidthCollection(Field)
Next
This hangs up on the Field.Width line, with "invalid procedure call or argument", which brings me back to how to reference a field name with a variable.
Any help would be greatly appreciated!
Try with:
Reports("ReportName")(VariableName).Width = 200

Excel Named Range Formula - Not Automatic Updating

I have a table in Excel that has column heading names (e.g. data_type1, data_type2, etc.). The data in this table changes based on parameters entered on another sheet, and they are pulled to charts which update dynamically.
As a convenience to a user who might be using this sheet I have added a 'user specified function' (non-vba) which also plots to one of the charts. By user specified function I mean I have three cells with dropdown lists. Two correspond to the table headings and one has a short list of operations that can be applied between the two selected data types (e.g. a user might select 'dataype1', '+', 'datatype2' which would produce a sum of the two in the final column of my table).
The user specified function is achieved by defining a named 'range/function' to match the drop downs with their respective column headers and then calls evaluate. See below:
=EVALUATE("="&ADDRESS(ROW('Raw Data'!XFD5),MATCH(user_in1,'Raw Data'!$A$4:$AF$4,0)) & user_operation & ADDRESS(ROW('Raw Data'!XFD5),MATCH(user_in2,'Raw Data'!$A$4:$AF$4,0)))
I name this 'user1_result' and then enter =user1_result in the final column of my table. This approach is nice because it calculates much faster than doing the same thing through building a UDF in VBA and then applying that UDF to every cell in a fairly long column.
Now here is my hangup, this works fine initially, but if the user makes a parameter change that affects one or both of the selected datatypes, the user specified column does not recalculate on-the-fly with the updated data. If the user re-toggles any of the dropdowns the data does recalculate. I am speculating this is from one of two things:
1) Excel does not recognize that a precedent of 'user1_result' has changed, and so for efficiency sake doesn't bother to recompute the column;
2) The 'Evaluate' function used in the named definition of 'user1_result' is not checked for updating, because it's not a normal function (doesn't show up through intellisense if you try to just add that to a cell).
So I am looking for some either confirmation or refutation of these speculations. In the case of confirmation I am hoping to get some advice on how to force the user specified column to update if its precedents change.
One solution is to have VBA do this checking for me and force the computation, but I would like to leave that as a last resort. So, non-VBA solutions preferred.
For posterity I'll answer the above question based on Mat'sMug's feedback:
Regarding the cause of the problem:
The reason the user specified column does not update is because the 'Evaluate' portion of the 'user1_result' named formula is intended to be used at the application level and not as a worksheet function. Because of this, Excel doesn't bother checking to see if its precedents change and ignores it for recalculation.
The problem's solution:
It was suggested to use VBA to watch for worksheet_change events, however, my problem requires that I do NOT use VBA. So, an alternative workaround that forces Excel to check precedents and recalculate the user specified function uses two steps. This functions as a pseudo worksheet_change stand-in.
First, I use a helper cell that performs a countif with an arbitrary counting condition. I don't need it to change, I just need it to share precedents with the inputs of 'user1_result'. So I have it count the number of cells in the first row of data that are larger than some constant:
=COUNTIF(A5:AK5,">100000")
The result of this computation doesn't matter, but in my case my data have small values and so this returns 0 always.
Second, I use a condition for the computation in the user specified column (the last column in my data table).
=IF($AO$1=$AO$1,user1_result)
Now, anytime my data table updates, the final column using the named function recomputes. Simple, and if using macros is not viable (for example due to a client/user's security concerns), this can sort of substitute for a worksheet change event.
I hope somebody out there gets use from this!

Coloring Excel Cell based on a table condition

I am going through the users of a system and reviewing if they have appropriate role names. I then completed an excel table that looks abit like this:
I'm trying to turn the table into a more readable format. I have made a pivot that looks like this:
But I'm not sure how to highlight the cells to reflect the 'Access Appropriate? Yes/No' column. Ideally, it should be colored yellow if the 'Access Appropriate?' = 'No'. I'm thinking of using VBA, but was wondering if there is an easier solution using formulas or pivot table?
Your pivoted data isn't an actual excel pivot table, is it? I know what the x mean, but where do they come from?
Two possibilities come to mind if you want a flexible setup without VBA, aswell as an rather simple VBA-approach that uses an UDF.
Quick'n'dirty (really dirty) would be to
use 1/0 instead of yes/no (you could write that into a helper column with an if-function)
create a new pivot with ROLE_NAME for columns, USER_NAME for rows and SUM or MAX of [Access appropriate] for values
that means: instead of your x you will end up having 1 and 0. Empty cells will still be empty.
conditional format the value-range, e.g. If 1 then green If 0 then yellow if "" then Nothing
Alternatively, you could build your output-table with formulas like INDEX, MATCH and VLOOKUP-formulas.
An additional Key-Column with USERNAME&ROLE_NAME will be needed
conditional format the value-range
VBA: Provided your Rows are distinct a user defined function could do the following
read data into a recordset IF that hasnt been done already (meaning: declared on module-level, the first function call will fill it)
access the data in your recordset with a Recordset.Filter based on your input parameters - USERNAME and ROLE_NAME, in your case
output a certain Field.Value based on your input parameter - Access Appropriate in your case
conditional format the TRUE/FALSE values you get (since this can't easily be done inside an UDF)

Custom code to fix #Error showing in SSRS reports

I have a few reports built using Report Builder 3 for MSSQL 2008 Reporting Services.
Some fields in my report are showing "#Error", instead of this I want to show only a simple "-". Is there any built-in function or custom code to overcome this?
I'd still really like to see your formula but you seem determined not to show it, so I'll take a wild stab at answering without it. I imagine that you are doing something like dividing the field on the current row by the field on the previous row. However, this would give you Infinity on the first line rather than #Error so there is something else going on. But let's run with this anyway since we don't have your formula.
The most common way to solve this is to check for Nothing being returned for the Previous function, usually indicating that you are on the first row (assuming your field always has data). This has the advantage of also working on fields that are not guaranteed to have a value.
=IIF(IsNothing(Previous(Fields!MyField.Value)), "-", Fields!MyField.Value / Previous(Fields!MyField.Value))
Here is another way you could do it using the row number, which will always check for the first row regardless:
=IIF(RowNumber(Nothing) = 1, "-", Fields!MyField.Value / Previous(Fields!MyField.Value))
This assumes that the error is being caused by the Value formula and not by some other mechanism such as applying an expression to other properties like Format, Color which is invalid when there is no previous row.