Is it possible to present / populate related data in predefined columns? - reporting-services

How can change the presentation of the data so I get the names o the princesses by two columns, shown in "Wanted output". Column grouping on Knight's name gives me a Princess column for each of the princesses names. I only want two columns since I know that a knight will never have more than two princesses.
The the data I get from my input source is shown below as "Input data". Unfortunately I cannot use SQL to manipulate the data, since the QUERY is based on FetchXML. The only tools I can use is what I'm getting from Reporting Services (I'm using Visual Studio 2015), so have that in mind while suggesting any solutions.
Technically thers's a 1:M relation between Knight and Princess, but there's a restriction in the system so that a knight will never have more than 2 princesess. A Knight can have 0, 1 or 2 princesses.
Input data
_________________________________
| Knight | Princess |
|_______________|_______________|
|_____Adam______|_____Anna______|
|_____Adam______|____Angelica___|
|_____Erik______|_____Erika_____|
|_____Erik______|______Eva______|
Output
_________________________________________________________________________________
| Knight | Princess 1 | Princess 2 | Princess 3 | Princess 4 |
|_______________|_______________|_______________|_______________|_______________|
|_____Adam______|_____Anna______|_____Angelica__|_______________|_______________|
|_____Erik______|_______________|_______________|_____Erika_____|_____Eva_______|
Wanted output
_________________________________________________
| Knight | Princess 1 | Princess 2 |
|_______________|_______________|_______________|
|_____Adam______|_____Anna______|___Angelica____|
|_____Erik______|_____Erika_____|_____Eva_______|
Any suggestions?

You can do this by using choose and lookupset on the dataset:
=Choose(1,LookupSet(Fields!Knight.Value,Fields!Knight.Value,Fields!Princess.Value,"InputData"))
=Choose(2,LookupSet(Fields!Knight.Value,Fields!Knight.Value,Fields!Princess.Value,"InputData"))
=Choose(3,LookupSet(Fields!Knight.Value,Fields!Knight.Value,Fields!Princess.Value,"InputData"))
etc.
In each column.

This is almost impossible, but you have lucked out by having a (quite reasonable) limit of 2 Princesses per Knight. Any more and you would be stuck.
I would use an Table, not a Matrix object for this. First column is the Knight.
The next column has a static Header "Princess 1", with expression:
=Min(Fields!Princess.Value)
The 3rd column has a static Header "Princess 2", with expression:
=Iif ( Min(Fields!Princess.Value) = Max(Fields!Princess.Value) , "" , Max(Fields!Princess.Value) )

You could make a table with a rowgroup by Knight and within that rowgroup body add a tablix with a columngroup by Princess. Only problem would be, that the column headers Princess 1..x would have to be somehow hard coded into the underlying table.

Related

how do i update a one to many map table?

the first is the sectors table that has an id and sector name like this
id | sector
1 | Government
2 | Education
The second is the employee table like this (simplified)
Id | name
1 | sam
2 | tom
Finally I have a sectorMap table (this is used to join the two tables above together) like this
Id | sectorid | employeeid
1 | 1 | 2
2 | 1 | 1
3 | 2 | 2
So in this instance, once I join everything together and view the sectors or each employee, it would show that tom has two sectors (government, education) and sam only has one (government)… hope that makes sense
My question is, within my application, the user has the ability to change these sectors by selecting from a multiple selection dropdown in html. For some reason I thought that by doing an update on duplicate expression would work, however seeing how I have multiple rows of data, I would need to delete all rows within the sectormap table that do not reflect the new selection and contain the selected employees id. What would be the best way of going about that?
For instance, in this case, lets say I open the application and see that tom has two sectors tied to him (government, education) and I only wanted him to have one (government). When I deselect education and select GO. The application returns a list to the server that contains (‘government’). How can I formulate an expression to delete the education sector row from the sectormap table that contains his id?
Your answer is in your question.
1st when you are deselecting education. You will get data of (‘government’). right?
So just invert your query. select those records which is not (‘government’), those are education.
So, education records are you can delete.
Hope this will help you. thanks:)

SSRS Report - Horizontally Sort Columns Across Column Groups

I am creating an unusual SSRS report that requires that the user be able to use parameters to select which of the (more than 250) fields appear in the report. So the number of columns in this report can vary greatly.
I've been mostly successful at implementing this, but am stuck at controlling how to change the order of the columns.
Here is (a simplified example) of my original data:
My data as a screen capture
CompanyID | Address | Website_URL | Date_Created | Date Modified |
1 |123 Main Street|www.fake.com | 3/14/2019 | 3/15/2019 |
2 |555 Park Ave |www.notreal.com|3/12/2019 | 3/13/2019 |
The first thing I've done is to unpivot my data within my dataset (i used cross apply to do this). The name of what the column used to be is kept in a column named something like "Col_1", and the value is kept in a column named something like "Val_1". The trick is, I have to do this multiple times, once for each data type that I'm dealing with. Because obviously you can't have dates and nvarchars in the same column. When I unpivot the data above, it looks like this:
CompanyID | Col_1 | Val_1 | Col_2 | Val_2 |
1 |Address |123 Main Street | Date_Created | 3/14/2019 |
1 |Website_URL |www.fake.com |Date Modified | 3/15/2019 |
2 |Address |555 Park Ave |Date_Created |3/12/2019 |
2 |Website_URL |www.notreal.com |Date Modified |3/13/2019 |
The point in doing this is now I can create a matrix is the SSRS report with the CompanyID as a row group. Then I create two adjacent column groups for Col_1, and Col_2, which have as their values Val_1 and Val_2, respectively.
Click here to see SSRS Groupings
Now, when this report runs, each column group (for example, Col_1) expands out to show all the column names I had under that column in my unpivoted data. This could be dozens of columns. This picture shows what my final data looks like. This is similar to what my original data looked like. But with the benefit of the fact that the columns are being displayed dynamically.
My resulting Matrix
So, the only problem I'm having is that the columns are stuck within their groups. Say I want to sort them alphabetically, I can only sort the nvarchars together, and the dates together. I cannot sort the across their groups. Is there a way I can do this?
The resulting Matrix I want, with columns sorted alphabetically
Thanks in advance for any ideas.
Using your original unpivoted data, the design of your report needs to have 4 column groups.
1.Address
2.Date created
3.Date modified
4.Website URL

Multiple taxonomy term repeating results in views. Remove repetition but keep the term

NOTE: I dont want to remove the repeating node, more like merging them.
I have a view that pulls a seminar content type along with the taxonomy term attached to the content type. In the content type the term reference field pulling the taxonomy term is a multivalue field. So whenever there is more than one taxonomy term attached to the node the view result is repeated. So using view and its api what I want is
What I have now when view pulls the result is
Nid Speaker name | Location | Time
----------------------------------
12 Sanjok Gurung| London | 1900
11 John | London | 1900
10 Sally | London | 1900
10 Molly | London | 1900
So the above table, Sally and Molly are term reference selected in the same node.
What I want is
Nid Speaker name | Location | Time
----------------------------------
12 Sanjok Gurung| London | 1900
11 John | London | 1900
10 Sally,Molly | London | 1900
I tried manipulating the results from views_pre_render but this method feels like it is so dirty. There should be a better clean solutions
You need to use this contrib module.
URL: https://www.drupal.org/project/views_aggregator
You can read the documentation from the below url. http://cgit.drupalcode.org/views_aggregator/plain/README.txt?id=refs/heads/7.x-1.x
This is not a view issue actually,
If you open the Manage Display of seminar content type and try to edit the display settings of entity reference FORMAT format drop-down select separator you can change what kind of separator you may want to choose from settings tab like (comma or dash)
Note: Make sure to edit the exact display mode (teaser or Full content or Default) which ever is used in the view.
May be this will resolve the issue.

Lookup and Relationship with multiple columns

I am completely new to Access, but I've done the tutorials, and have some VBA experience with Excel, so I shouldn't be hopeless.
I haven't progressed to forms yet, right now I'm focusing on getting the tables defined and populated, and relationships defined.
I've changed the actual tables in the example here, but the context and problem hold.
Table 1 is Food. Other than the autofield key, it has two fields
FoodCat FoodType
Fruit banana
Fruit apple
Fruit pear
Meat lamb
Meat beef
Meet Chicken
Vegetable Broccoli
etc....
This table is used by another table, in a lookup and relationship setup.
It is easy to set it up so the other table has a field that is restricted to entries with the items in the FoodCat Field (although it is repetitive). I can also restrict the next field to entries with the FoodType Field, but this gives me all the choices.
What I'd like to do, in the new table, is restrict the FoodType choice to the entries that have a matching FoodCat choice.
So, if the item selected on the new table under FoodCat is Meat, I only want the FoodType choices to be lamb, beef, or chicken.
Is this even possible within the table? Do I need to use Forms to get this done?
Answering to your comment:
When you use "Lookup" fields" you are forcing a new relation between the tables.
The best way to avoid the problems listed in the Ten Commandments of Access (specifically: The evils of the lookup fields in tables ) is to create the relations manually, and then use them to create the adequate "lookup" control in a form or report.
Let's say you have the following tables:
tblCategories
id | catName
---+-----------
1 | Fruit
2 | Meat
3 | Vegetable
tblFood
id | idCat | foodName
---+-------+-------------
1 | 1 | Apple
2 | 1 | Banana
3 | 2 | Lamb
4 | 2 | Beef
5 | 3 | Broccoli
In this example is obvious that there's a one to many relation between these two tables, and that the idCat field in tblFood is a foreign key. You can create this relation by hand in the "Relations" window.
With the following query you can get both the foodName and catName fields properly (a good thing to build reports):
select f.*, c.catName
from tblFood as f
inner join tblCategories as c on f.idCat = c.id;
This would throw something like this:
id | idCat | foodName | catName
---+-------+----------+------------
1 | 1 | Apple | Fruit
2 | 1 | Banana | Fruit
3 | 2 | Lamb | Meat
4 | 2 | Beef | Meat
5 | 3 | Broccoli | Vegetable
which is a nice and useful query that you can use in a report... without the need of using Combo Boxes in the report.
So: How on earth to build a control, for example, a ComboBox, that filters only the foodName values depending on a catName value?
First: Create the form
Then: Create a Combo Box and put this in the RowSource property:
select id, catName from tblCategories
Set the control to have two columns, and column widths: 0, 10. This will make the id column in the drop-down list "invisible". Be sure to know the name of this combo box (let's say it is named comboBox01).
Now, create a second combo box, keep the RowSource property empty, and set the column widths to 0, 10. Also be sure to know the name of this second combo box (let's say it is named comboBox02).
And now let's make VBA do what you need: On the properties sheet of the comboBox01 control, look for the afterUpdate event, clic on the ellipsis button, select "VBA code" and write the following
Sub comboBox01_afterUpdate() ' This is added automatically by the VBA editor
strSQL = "select id, foodName from tblFood where idCat=" & comboBox01.Value
comboBox02.rowSource = strSQL
comboBox02.Requery
End Sub ' This is added automatically by the VBA editor
"Lookup controls" (no "lookup fields") are very useful when used in forms. They can save a lot of headaches to the users of your database (you included). But I strongly recommend you to avoid creating them directly in the tables.
Hope this helps.
Yes, it is possible to do within the table. However, it's easier to do through a form and it's more practical to do through a form. You NEVER, EVER want your user interacting directly with a table.

SSRS report formatting a table to display data side by side

I am trying to achieve the following layout for my report based on one query.
+----+-------+----+-------+
| ID | Name | ID | Name |
+----+-------+----+-------+
| 1 | Danny | 2 | Dave |
| 3 | Sue | 4 | Jack |
| 5 | Rita | 6 | Sarah |
+----+-------+----+-------+
So I basically want one table, printing my data from left to right to save space on my page, rather than it printing one line and wasting all of the space on the right side of the paper, possibly even go 3 times across the width.
This is my data: http://sqlfiddle.com/#!3/5c911/1
I was maybe thinking a table with 4 columns. Cols 1 and 2 contain the odd row numbers, Cols 3 and 4 contain the even row numbers.
How could I achieve this, I did try something with the MOD function but it didn't seem to work properly, or I misunderstood what was happening.
Related:
How can I display two rows worth of data on one line side-by-side in Report Designer?
Thanks,
To print your data from left to right in a multi-column format, you need to fake it using multiple tables. To implement this hack, create the same number of tables as columns you want side by side that all point to your data set. On the Detail row of the first table, for the Visibility-Hidden property use the following formula:
=IIF((RowNumber(Nothing) Mod 4) = 1, False, True)
where 4 is the number of tables (columns) you have.
Do the same for each table, incrementing what the formula is equal to (so for the second column (RowNumber(Nothing) Mod 4) = 2 and so forth). In the last table (column) the formula equals 0.
This alternately hides the detail row, only displaying the appropriate rows for that column number.
You can achieve that look with query.
SELECT std1.id AS Student_Id,
std1.NAME AS Student_Name,
std2.id AS Student_Id,
std2.NAME AS Student_Name
FROM students std1, students std2
WHERE (std2.id - std1.id = 1
AND std1.id %2 = 1);