Is it possible to add multiple SetExpressions within an IF statement? - qlikview

I am having troubles trying to make a graph work. I am not entirely sure if this is possible, thus me asking here. I have below graph, which has the expression:
=Count{<Year='2014','2015','2016'},Month='Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'}>}DISTINCT sicknumber)
So it doesnt change with whatever selection has been made in the filters. it always shows 2014, 2015, 2016
I want to be able to make the graph non static based on the filter that is given. If I select year 2015 I want to show the previous year and the year after. so when selecting 2013 I want to see 2012, 2013 and 2014. I have made the following expression:
=
if(Jaar = '2016',(Count({<Jaar={'2015','2016'},Maand={'Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'}>}DISTINCT Ziekte_Volgnummer)),
if(Jaar = '2015',(Count({<Jaar={'2014','2015','2016'},Maand={'Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'}>}DISTINCT Ziekte_Volgnummer)),
if(Jaar = '2014',(Count({<Jaar={'2013','2014','2015'},Maand={'Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'}>}DISTINCT Ziekte_Volgnummer)),
if(Jaar = '2013',(Count({<Jaar={'2012','2013','2014'},Maand={'Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'}>}DISTINCT Ziekte_Volgnummer)),
if(Jaar = '2012',(Count({<Jaar={'2011','2012','2013'},Maand={'Jan','Feb','Mrt','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'}>}DISTINCT Ziekte_Volgnummer)))))))
it seems however that it ignores the set expression and just show the year given in the filter. How would I go around this.
When using the same statement to just calculate to total unique values in a text object, it does seem to be able to calculate the correct value there.
how would I go around this, of is it even possible?
thanks in advance

=Count({<Jaar={$(=Max(Jaar) - 1), $(=Max(Jaar)), $(=Max(Jaar) + 1)}, Maand>} DISTINCT Ziekte_Volgnummer)
Seems to be the right answer.

Related

Report builder (SSRS) SWITCH statement blank values

For a report I'm building, there are fields that are dependent on a user selecting to add additional people to their policy (named in the dataset as dependent1, dependent2, etc).
We need to determine whether these dependants are adults or children for reporting. This will be done via DOB and a DateDiff which I understand
Currently, I can get the report to show ADULT or CHILD if data is present, however if there isn't any data I can't return a "" value, it just defaults to ADULT.
I'm using:
=Switch(DateDiff("yyyy", Fields!Dependant1DoB.Value, Fields!Policy_Start_Date.Value) < 18, "CHILD",
DateDiff("yyyy", Fields!Dependant1DoB.Value, Fields!Policy_Start_Date.Value) >= 18, "ADULT",
DateDiff("yyyy", Fields!Dependant1DoB.Value, Fields!Policy_Start_Date.Value), "")
I also created another column which uses the DateDiff between Fields!Dependant1DoB.Value & Fields!Policy_Start_Date.Value to show the number of years. This works and returns a number. however for some unknown reason where there's no data it still returns "2019" which may be effecting it? I've tried including this in the Switch statement (DateDiff("yyyy",Fields!Dependant1DoB.Value,Fields!Policy_Start_Date.Value)=2019, "")) but this still doesn't work.
Someone please help as this is driving me loopy!
You need to first check for nothing and then apply the switch function, example below:
=IIF(IsNothing(Fields!Dependent1DoB.Value),"",
Switch(
DateDiff("yyyy",Fields!Dependent1DoB.Value,Fields!Policy_Start_Date.Value)<18, "CHILD",
DateDiff("yyyy",Fields!Dependent1DoB.Value,Fields!Policy_Start_Date.Value)>=18, "ADULT"
)
)

How to change SQL WHERE clause through excel?

I have build a SQL query to provide me historical price data of a product, which I intent to use in excel (pivot, graphs, all of that fancy excel stuff).
The problem now is that, due to the nature of many products and many price changes, I can not get all the products loaded that I intent to.
I somehow need to tell excel that has to change a couple numbers in the connected SQL query, i.e. through a text box and then load the query again. Otherwise I will always open up the query editor in excel and change it manually, which takes quite a bit.
I reckon I will have to use some sort of macro or VBA, but I have never used it. If anyone could refer an article that would be great, as i could not find anything helpful.
Some code:
WHERE
PD.Product_Id = '11761476' < I will have to change that number
AND
PSPH.[Valid_To] > '2018-01-01'
ORDER BY
PSPH.[Valid_To]
To manipulate the SQL string, you could do something like this..
pid = "11761476"
validto = "2018-01-01"
SQLtemplate = "WHERE PD.Product_Id = '[prodID]' AND PSPH.[Valid_To] > '[validto]' ORDER BY PSPH.[Valid_To]"
Sql = Replace(SQLtemplate, "[prodID]", pid)
Sql = Replace(Sql, "[validto]", validto)
but before you can use that, you'll need to follow #Foxfire's advice and record a macro while you're changing it manually to see exactly what needs to change, and how.
You can put this instead in the connection:
WHERE
PD.Product_Id = '11761476' < ?
AND
PSPH.[Valid_To] > '2018-01-01'
ORDER BY
PSPH.[Valid_To]
And then save the connection.
The first time it will run, a prompt will ask you where to find the parameter, and you can choose the cell.
Let me know if it works!
Cheers,
Arnaud

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.

Qlik sense ignore filters / selections

Using qlik sense
I have the following measure
RangeAvg(Below(Count( Distinct {1< Year=>} [OrderID]), 0, 52))
I still need when a user selects a year from the filer pane , the measure is unaffected
however using the Year= does not work
Any ideas team please?
The set identifier of 1 represents "the full set of all the records in the application, irrespective of any selections made." If you want all user selections to be accounted for except for Year, simply change the set identifier to $ (assuming you've not set up and used any other alternate states). The $ set identifier refers to the default state; the one that selections are made in by default when the user selects something in the interface.
If you want to ignore all filters but the year you can try this following code:
RangeAvg(Below(Count(Distinct{1<Year = p(Year)>} [OrderID]), 0, 52))
p function mean all possible values
For more information, you can read this help section from the Qlik site

MOSS 2007: What is the source of "Directories"?

I'm trying to generate a new SharePoint list item directly using SQL server. What's stopping me is damn tp_DirName column. I have no ideas how to create this value.
Just for instance, I have selected all tasks from AllUserData, and there are possible values for the column: 'MySite/Lists/Task', 'Lists/Task' and even 'MySite/Lists/List2'.
MySite is the FullUrl value from Webs table. I can obtain it. But what about 'Lists/Task' and '/Lists/List2'? Where they are stored?
If try to avoid SQL context, I can formulate it the following way: what is the object, that has such attribute as '/Lists/List2'? Where can I set it up in GUI?
Just a FYI. It is VERY not supported to try and write directly to SharePoint's SQL Tables. You should really try and write something that utilizes the SharePoint Object Model. Writing to the SharePoint database directly mean Microsoft will not support the environment.
I've discovered, that [AllDocs] table, in contrast to its title, contains information about "directories", that can be used to generate tp_DirName. At least, I've found "List2" and "Task" entries in [AllDocs].[tp_Leaf] column.
So the solution looks like this -- concatenate the following 2 components to get tp_DirName:
[Webs].[FullUrl] for the web, containing list, containing item.
[AllDocs].[tp_Leaf] for the list, containing item.
Concatenate the following 2 components to get tp_Leaf for an item:
(Item count in the list) + 1
'_.000'
Regards,
Well, my previous answer was not very useful, though it had a key to the magic. Now I have a really useful one.
Whatever they said, M$ is very liberal to the MOSS DB hackers. At least they provide the following documents:
http://msdn.microsoft.com/en-us/library/dd304112(PROT.13).aspx
http://msdn.microsoft.com/en-us/library/dd358577(v=PROT.13).aspx
Read? Then, you know that all folders are listed in the [AllDocs] table with '1' in the 'Type' column.
Now, let's look at 'tp_RootFolder' column in AllLists. It looks like a folder id, doesn't it? So, just SELECT the single row from the [AllDocs], where Id = tp_RootFolder and Type = 1. Then, concatenate DirName + LeafName, and you will know, what the 'tp_DirName' value for a newly generated item in the list should be. That looks like a solid rock solution.
Now about tp_LeafName for the new items. Before, I wrote that the answer is (Item count in the list) + 1 + '_.000', that corresponds to the following query:
DECLARE #itemscount int;
SELECT #itemscount = COUNT(*) FROM [dbo].[AllUserData] WHERE [tp_ListId] = '...my list id...';
INSERT INTO [AllUserData] (tp_LeafName, ...) VALUES(CAST(#itemscount + 1 AS NVARCHAR(255)) + '_.000', ...)
Thus, I have to say I'm not sure that it works always. For items - yes, but for docs... I'll inquire into the question. Leave a comment if you want to read a report.
Hehe, there is a stored procedure named proc_AddListItem. I was almost right. MS people do the same, but instead of (count + 1) they use just... tp_ID :)
Anyway, now I know THE SINGLE RIGHT answer: I have to call proc_AddListItem.
UPDATE: Don't forget to present the data from the [AllUserData] table as a new item in [AllDocs] (just insert id and leafname, see how SP does it itself).