How to combine multiple table results into one using FetchXml - report

I am using CRM 2013 Online. I want to generate a report on Opportunity entity like below:
CampaignCode Open Opportunity Count Won Opportunity Count Lost Opportunity Count
CC1 3 5 1
CC2 0 2 3
Here the results are group by on "CampaignCode" column which is a lookup. Using FetchXml I am able to get 3 tables like below:
CampaignCode Open Opportunity Count
CC1 3
CC2 0
CampaignCode Won Opportunity Count
CC1 5
CC2 2
CampaignCode Lost Opportunity Count
CC1 1
CC2 3
But I am not able to combine these 3 tables into 1. How can I do this?

For what i know it's not possible to merge multiple datasets in a single table. I will give your question a plus because I'm interested in this too.

Related

Merge two data frames - no unique identifier

I would like to combine two data frames. One is information for birds banded. The other is information on recovered banded birds. I would like to add the recovery data to the banding data, if the bird was recovered (not all birds were recovered). Unfortunately the full band number is not included in the banding data, only in the recovery data, so there is not a unique column to join them by.
One looks like this:
GISBLong
GISBLat
B Flyway
B Month
B Year
Band Prefix Plus
-85.41667
42.41667
8
5
2001
12456
-85.41655
36.0833
9
6
2003
21548
The other looks like this:
GISBLong
GISBLat
B Flyway
B Month
B Year
Band
R Month
R Year
-85.41667
42.41667
8
5
2001
124565482
12
2002
-85.41655
36.0833
9
6
2003
215486256
1
2004
I have tried '''merge''', '''ifelse''', '''dplyr-join''' with no luck. Any suggestions? Thanks in advance!
you should look up rbind(). That might do the trick. For it to work the data frames have to have the same columns. I'd suggest you to add missing columns to your first DF with dplyr::mutate() and later on eliminate useless rows.

Count no. of categories within categories in my df in R

Each row of data in my df is from a study (or "Article"). Each Article has a sponsor ("Sponsor") who may have sponsored a number of the articles in my dataset.
I want to produce a summary table to show how many articles each Sponsor has sponsored in my dataset.
I hope you can help!
many thanks!!!!
Annabel
What I presume your dataframe looks like:
df=data.frame(article=1:10,sponsor=letters[round(runif(10,1,5))])
head(df)
article sponsor
1 1 a
2 2 b
3 3 e
4 4 d
5 5 e
6 6 b
How you could quickly check the number of articles per sponsor:
table(df$sponsor)
I'm not sure what you want to do exactly, but
I guess what you are looking for is:
table(df$Sponsor)
If you want the value that occurs the most frequent, you can use:
names(sort(table(df$Sponsor), decreasing=TRUE))[1]
next time, please try to provide a MWE so it is easier for us to help.

How to select product with multiple categories

According my title of question so i have structure for Access database like this:
Category
categoryid categoryname
1 one
2 two
3 three
Product table:
productid productname categories
1 one 1,2,3
2 two 3
3 three 1,2
When i have categoryid is 1 I dont know the way to select product have multiple categorise. Because when i use In operator,i am getting some error..
Select * from product where categories In (categodyid) because cannot compare a collection with one value.
i'm stuck at here! Please help me! Thanks.
First of all, your tables are not normalized. Look at the Categories column in Product Table. Each cell should have only one value. By allowing multiple values, you risk various problems including update/insert anomalies and what you are seeing now. You also make it very difficult to do selects and other operations. Instead, think about normalizing your tables with this example:
Category
categoryid categoryname
1 one
2 two
3 three
Product
ProdductId ProductName
4 prod1
5 prod2
6 prod 3
Category_Prod
CategoryId ProductId
1 3
1 4
2 3
The third table acts as a way to remedy the many to many pattern. If you have any questions on how to do this or how to use it, let me know
This is a classic parent-child one-to-many relationship. You need a [ProductCategory] table to associate a given Product with multiple Categories:
productid categoryid
1 1
1 2
1 3
2 3
3 1
3 2

Using two datasets in a single report using SQL server reporting service

I need to show a report of same set of data with different condition.
I need to show count of users registered by grouping region, country and userType, I have used drill down feature for showing this and is working fine. Also the reported data is the count of users registered between two dates. Along with that I have to show the total users in the system using the same drill down that is total users by region, country and usertype in a separate column along with each count (count of users between two date)
so that my result will be as follwsinitialy it will be like
Region - Country - New Reg - Total Reg - User Type 1 - UserType2
+ Region1 2 10 1 5 1 5
+ Region2 3 7 2 4 1 3
and upon expanding the region it will be like
Region - Country - New Reg - Total Reg - User Type 1 - UserType2
+ Region1 2 10 1 5 1 5
country1 1 2 1 2 - -
country2 1 8 1 8 - -
+ Region2 3 7 2 4 1 3
Is there a way I can show my report like this, I have tried with two data sets one with conditional datas and other with non conditional but it didn't work, its always bing total number of regiostered users for all the total reg columns
Unless I'm mistaken, you're trying to create an expandable table, with different grouping levels? Fortunately, this can be easily done in SSRS if you know where to look. The totals on your example don't seem to match up in the user columns, so I may have misunderstood the problem.
For starters, set up your query to produce a single dataset like this:
Region Country New Reg - Total Reg - User Type 1 - User Type 2
Region1 country1 1 2 1
Region1 country2 1 8 1
Region2 country3 2 4 1 1
Region2 country4 1 3 1
Now that you've got that, you want to set up a new table with the fields "NewReg", "TotalReg", "UserType1" and "UserType2". Then right-click the table row, and go to "Add Group > Row Group > Parent Group". Select "Country" in the Group by and click okay. Then, repeat this process and select "Region". This time however, tick the "Add group header" box. This will insert another row above the original.
Now, for each of your fields ("NewReg", "TotalReg" etc), click in the new row above and select the field again. this will automaticaly add a Sum(FieldName) value into the cell. This will add together all the individual row totals and present a new, grouped by region row when you run the report.
That should give you the table you require with the data aggregated correctly, so all you need to do is manage the show/hide the detail rows on demand.
To do this, select your detail row (the original row) and right-click "> Row visibility". Set this to "Hide". Now, select the cell that contains the "Region" and take note of its ID using Properties (for now, let's assume it's called "Region"). Click back onto your detail row and look at the properties window. At the bottom you'll see a "Visibility" setting. In there, set "InitialToggleState" to False and "ToggleItem" to the name of your region group's cell (i.e. "Region").
Now all that should be left is to do the formatting etc and tidy up.
I have solved this problem by taking all the records from DB and filtering the records to collect new reg count by using an expression as following
=Sum(IIF(Fields!RegisteredOn.Value >Parameters!FromDate.Value and Fields!RegisteredOn.Value < Parameters!EndDate.Value , 1,0))

SQL Server - Group by, having and count in a mix

I have a database with a long list of records. Most of the columns have foreign keys to other tables.
Example:
ID SectorId BranchId
-- -------- --------
5 3 5
And then I will have a table with sectors, branches ect.
My issue:
I want to know how many records which has sector 1, 2, 3 ... n. So what I want is a group by Sector and then some count(*) which will tell me how many there is of each.
Expected output
So for instance, if I have 20 records the result might look like this:
SectorId Count
-------- -----
1 3
2 10
3 4
4 6
My attempts so far
I do not normally work a lot with databases and I have been trying to solve this for 1.5 hours. I have tried something like this:
SELECT COUNT(*)
FROM Records r
GROUP BY r.Sector
WHERE r.Date BETWEEN '2011-01-01' AND '2011-12-31'
But... errors and problems all over!
I would really appreciate some help. I do know this is probably very simple.
Thanks!
The sequence of your query is not correct; it should be like this: -
SELECT COUNT(*)
FROM Records r
WHERE r.Date BETWEEN '2011-01-01' AND '2011-12-31'
GROUP BY r.Sector
The output will be only counts i.e.
count
-----
3
10
4
6
If you want to fetch both sector and count then you need to modify the query a little
SELECT r.Sector, COUNT(*) as Count
FROM Records r
WHERE r.Date BETWEEN '2011-01-01' AND '2011-12-31'
GROUP BY r.Sector
The output will be like this: -
Sector Count
------ -----
1 3
2 10
3 4
3 6
Your query was partially right,But it needs some modification.
If I write this way:-
SELECT r.SectorID,COUNT(*) AS count
FROM Records r
WHERE r.Date BETWEEN '2011-01-01' AND '2011-12-31'
GROUP BY r.SectorID
Then output will be:-
SectorID Count
1 3
2 10
3 4
4 6

Resources