Filter the data in one query based on the result from another query in Cognos - cognos

I need to use a column data obtained in a query in Q1 as a filter in Q2. Is there a way? Can anyone please suggest? I'm a beginner.
PS: Need to pull the report based on the country.
I have 3 columns in Q1 ---> User Name, User ID, User email
3 columns in Q2--> User ID, user location and user country
A join condition between Q1.userID and Q2.userID works.
but I need to create a report that pulls the users details based on the country I select.

It would be best to do this via a proper model instead of modelling in the report. That being said, in a pinch, you could set the allow cross join query hint on both queries and create a filter similar to:
[Query1].[UserID]=[Query2].[UserID] and [Query2].[Country]=?p_Country?

Related

Cassandra: filtering based one specific value in a set

I have a data table in Cassandra and one of the columns is:
customer_favourites, with each value being of type set and it has the details of each customer's favourite foods. For example one customer could have {'Mexican', 'Italian', 'Indian'} and another customer could have {'Mexican', 'French'} and another could have {'Mexican'}.
I have the following code:
SELECT customer_id, customer_fname, customer_lname FROM customers WHERE customer_favourites CONTAINS ‘Mexican’ ALLOW FILTERING;
I want it to filter on those customers whose favourite food is ONLY Mexican, but right now it's returning the details of every customer who has Mexican as one of their favourite foods. How do I filter my query to return customer who like ONLY Mexican food?
Naive approach: You need to use customer_favourites = {'Mexican'}...
Better approach - create secondary index on the corresponding field, using the FULL keyword, and then use customer_favourites = {'Mexican'}.
Best approach - create a separate table with customer_favourites as partition key, and search users in it (column should be frozen). One of the problems with this approach would be the data skew, as number of favorite foods is relatively small, and quite imbalanced.
Alternative approach - reconsider the use of the Cassandra, if you need to search by non-partition key very often.

Is there a way to insert data to a user made column in for SQLite?

I am working on a Python program that takes in user input and stores the inputs to a database using SQLite. A problem that I run into is that I want to give the option to the user to make a new column in the table, but I don't know how to insert/edit/delete/search data to the new column. Is there a good way to do this in Python? My first idea is to make a list of all the column names and make a separate list to check which columns the user wants to insert/search to and do the query from there, but that does not seem to be a good idea to me because it makes the user experience not good since it basically asks the user what to input every time the user wants to input something. Please help. Thank you.
Edit: This is an example scenario:
Say, a table has 4 columns: name, address, date of birth, and job. There are functions that ask for user input for those columns and store it to the database. Then, the user adds another column, say phone number. How can you insert/search data to/from the phone number column?
You can add a new column to your table using :
ALTER TABLE useTable ADD COLUMN phone TEXT DEFAULT '-';
-- Insert Data
INSERT INTO userTable (name,address,dateBirth, phone)
VALUES(searchedName,searchedAddress,searcheDateBirth, searchedPhone);
-- Search for Data, eg phone
SELECT * from userTable where name like '%Sky%'
see doc for restictions

power query reverse data propagation

Suppose I have a big master table with columns: product, type, price, and note.
type includes: Fruit, Vegetable
I would like to create a filtered table for Fruits only in a separate sheet SF.
So far it is easy.
I would like to be able to edit notes in the sheet SF and require that changes are propagated to the master table.
Do you please know a way to do so? (power query is not necessary if you know another solution)
Best wishes
L.

An outer join Excel Power Pivot Pivot table?

I have a PowerPivot with two tables one contains a list of facilities, their type (active/inactive) and whether they belong to org A or org B (FaciltyID|Active/Inactive|ORG)
Another table has a list of users and facitilites assigned to them + their org, so it looks like (userID|FacilityID|ORG) where each userID is repeated the number of times that=the number of facilties it has.
Initially I needed to report the number of facilities active and easily built a PivotTable for it.
Now I need to get a list of the facilities that each user is missing , so I need to basically do an outer join between the the tables for each user and I just can't figure out the way to do it! I joined both table on the FacilityID and am able to see whether they have inactive facilties, but can't figure out a way to show all the facilities they are missing!
Thanks
Nonexistence is hard. This is not the sort of thing that is best solved through measures, but through modeling. In your source, you should cross join Facility and User to get FacilityUser. In FacilityUser, every user has 1 row with every facility, and you add a flag to indicate whether the user is or isn't assigned to that facility. Then your problem becomes one of filtering on that flag value. This is solvable in DAX, but you don't want to do that.

Powerpivot duplicating values

I have two tables:
First table contains sales pipeline information for accounts (contains pipeline ID, accountID, and pipeline value). Each account IDs have multiple pipeline ID
Second table includes the number of employees per account.
I included these tables to powerpivot, and I created relationship based on account ID.
I would like to create pivot that tells by Number of employees & Pipeline value by account ID and PipeID.
However, when implemented, it repeates all pipeID for each account. Even those pipeIDs which are not related to the account.
http://i.stack.imgur.com/WY1Ga.png
Could someone point me to a right direction to how I tweak the pivot to show only relevant pipeID?
I would appreciate any help you could provide...
thank you!
The numbers repeat in your pivot table because Number of Employees is not related to Pipeline ID. This is Excel's default reaction to missing relationships. To get rid of the repeating numbers and keep this pivot table as is you need to find a way to relate number of employees to a pipeline ID.
If I were modeling this, I would have a separate table that is just distinct Account IDs, to make it it's own dimension. Then have your two tables you mentioned in the question.
If you were simply writing a query against this data, how you would connect pipeline ID to number of employees? To which pipeline should an employee be attached ? If there is a way to do this manually/in a query, adjust your two tables to both include the fields on which you would join. I don't think you would be able to relate Number of Employees to Pipeline ID, so I would remove Pipeline ID from the pivot table. Then the numbers should be correct. You would want to create another pivot to show pipeline by pipeline ID per account.

Resources