SRSS - Double GROUPS from same SQL request in two columns - sql

I'm completly stuck as Im new to SSRS.
I have a set of data formed like this :
A "Selection" of rights concerns several "Companies"
A "Company" contains several "Conductors"
A "Selection" is accessible by several "Accessors"
My SQL results look like this :
SELECTION_NAME
COMPANY_NAME
CONDUCTORS_NAME
ACCESSORS_NAME
SELECT_A
COMPANY_A
John
Maggie
SELECT_A
COMPANY_A
John
Lucy
SELECT_A
COMPANY_A
John
Veronica
SELECT_A
COMPANY_A
Bob
Maggie
SELECT_A
COMPANY_A
Bob
Lucy
SELECT_A
COMPANY_A
Bob
Veronica
SELECT_A
COMPANY_AA
Luke
Maggie
SELECT_A
COMPANY_AA
Luke
Lucy
SELECT_A
COMPANY_AA
Luke
Veronica
as you can see, conductors are repeated as many time as there are accessors to the relative Selection.
I would like to have, in my SSRS report, a relatively same structure BUT I want that conductors, and associated accessors, listed each ONCE.
And, grouping by Selection > Company.
It could be something like this :
SELECTION_NAME
COMPANY_NAME
CONDUCTORS_NAME
ACCESSORS_NAME
SELECT_A
COMPANY_A
John
Maggie
Bob
Lucy
Veronica
COMPANY_AA
Luke
Maggie
Lucy
Veronica
I tried to create 2 datasets and use LOOKUP but if it list conductors only once, at each line, I got the first accessor repeated, no more lines, no other accessors names..
How can I display conductors in 3rd column, regardless number of accessors, grouping by SELECTION > Company AND only SELECTION accessors in the 4th one regardless conductors and also grouping by SELECTION > Company (even if accessors will be repeated on each companies lines of the same Selection) ?
Is this possible with SSRS ?
I'm using Microsoft Visual Studio 2010.
Thank you

You do not need to do anything complicated.
Create a dataset that gives you the table you showed at the start of your question.
Then add a tablix (table) to your report.
There are several ways to create the design but if you start by dragging accessor onto the detail row. Now, under the main design windows you will see a section with Row Groups listed, you will only have one called "Detailed", now you can either drag the Conductor just above the detail row group, or you can right-click the detail row group and add a parent group and select Conductor. Repeat to add row groups for the other two columns.
The SSRS documentation explains this process in more detail
https://learn.microsoft.com/en-us/sql/reporting-services/lesson-6-adding-grouping-and-totals-reporting-services?view=sql-server-ver15
He's quick GIF using your data to show you the basic steps. Notice that I drag the field names just above the existing row group name so that a blue line appears, then I release the mouse button.

I didn't find any ways to do it with only groups..
I created a subreport with accessors (linked to Selection > Company > Accessors).
I added it in a new column in the main report which only displays "Conductors" (Selection > Company > Conductors).
The only negative point is that it's really long charging report.. :/

Related

How to check string similarity from two tables with multiple words input in BigQuery

I have two tables containing a list of company names. The first one would be the index table therefore the value inside would be clean and the format is consistent. The second table contains user-input company information and therefore there might be typos and format inconsistencies.
The first one (the index table) looks similar to this:
company_name | industry
Apple Inc Technology
Amazon Inc Retail
Kraft Heinz Food Processing
New York Life Insurance Company Insurance
Tesla Inc Tesla
Walmart Inc Retail
The second table (user input table) looks similar to this
company_name
Apple
Apple Inc.
Amazon, Inc
Kraft
New York Life
Tsla
Walmart
Notice that the second table does not have the industry column since the main goal would be to add the industry column to the second table, but since there is no key we can't simply join the two tables.
I think the first step would be to compare the similarity between the company_name and if it is similar enough we can just assume it is the same.
I have done some research and I think we would need to use Levenshtein Distance. Honestly, I am not very familiar with that method, but from my limited understanding, I wonder if it is applicable for inputs containing multiple words (e.g New York Life Insurance Company) or it is just effective for one-word input (e.g Apple).
Any suggestions or guidance would be greatly appreciated.

What is most efficient way to find ‘inverse' of getting all records that match particular criteria

I am trying to find the most efficient way to find ‘inverse' of getting all records that match particular criteria
I.e. find all predefined criteria from a set that a particular record matches
I have a table of 'target' criteria that has many records - each built using a querybuilder javascript component - so each target record has its criteria stored as a json string in a field.
I also have a standard 'person' table
It is straight forward to query how many people fit a particular target.
What I am trying to do is get all targets that match a particular person
Is there a more efficient way than just running each target's criteria against a person?
Open to suggestions beyond just sql - e.g. caching , hashing or building up some kind of lookup table/file
Edit:
Hopefully tables below clarify this issue. If I parsed and ran the 'Good Eyesight' target criteria I would expect to return both Bob and Sue
But I want to know that Bob matches the 'Young People' and 'Good Eyesight' target. I will have thousands of users and probably up to 50 active targets.
Table 1: Person
ID Name Age Fav_Vegetable
---------------------------------
1 Bob 20 Carrot
2 Sue 40 Carrot
Table 2: Target
ID Name Criteria_JSON
---------------------------------
1 Young People {"rule": "young_age", "selectedOperator": "<","selectedOperand": "Age","value": "30"}
2 Old People {"rule": "old_age", "selectedOperator": ">","selectedOperand": "Age","value": "30"}
3 Good Eyesight {"rule": "vegetable","selectedOperator": "equals","selectedOperand": "Fav_Vegetable","value": "Carrot"}
The answer I have come up with is to run all targets against all people and maintain an index type table of the results.
i.e. have a table TargetIndex with columns targetId, personId
Then when I need to know the targets for a particular person I can just check against the TargetIndex table rather than rerunning queries.
Obviously these results would need to be refreshed as the target or people records change - - probably whenever a target is added/edited and refreshed periodically (hourly/nightly?) to pick up changes in people
Thanks for people's thoughts

If row contains value, return value from column A value, for all rows

I've seen some similar posts, but none with a really helpful answer for my particular issue. I'm a programmatic advertising data analyst, so i'm trying to associate a many-to-many relationship.
We run "personas", which is a group of apps. A persona has many apps, and apps have many personas. I have the data organized by persona: each row is a persona, and each column in that row contains one of the apps comprising that persona. Each persona has a different number of apps. i.e.
Row Persona App 1 App 2 App 3
1 Casino Persona "Slot Kings" "Wild Casino" "Real Gambling App"
2 RPG Persona "Dragon Valor" "KOTOR"
3 Sports Persona "MLB: The App" "Real Soccer" "Hockey Fans 2016"
4 Gen-X Females "Scrapbook App" "Baby Monitor" "PostMates"
So i know which apps belong to each persona. I'm now trying to determine which personas belong to each app. I'd like to create another worksheet that switches "apps" and "personas." e.g.
Row App Persona 1 Persona 2 Persona 3
1 Slot Kings "Casino Persona" "Slot Persona"
2 KOTOR "RPG Persona" "Star Wars Fans" "SciFi Persona"
3 MLB: The App "Sports Persona" "Baseball Fans"
I can't figure out any way to do this an insane nested statement, VBA, or a similarly crazy array formula.
I understand what you're asking for. However, trying to rearrange your data with either formulas or VBA would take a lot of time and effort; and is also quite unnecessary.
The layout of your data is good for viewing, but is not suitable for any kind of data analysis. If you want to perform analysis, data should always be stored in a database format. See this article for more info:
https://support.office.com/en-us/article/Guidelines-for-organizing-and-formatting-data-on-a-worksheet-90895CAD-6C85-4E02-90D3-8798660166E3
For your data, you should just have 2 columns, one for Persona and one for App. Then on every row, you list just one possible combination of Persona and App. It doesn't matter in what order you place the data.
With your data set up correctly, you can now create PivotTables that automatically arrange your data either way. It's also possible to easily count the number of apps in each persona and vice versa and then also create charts. Look up PivotTables and PivotCharts for more info.
To create the top left table, put Persona into the Rows field and then put App into Rows field as well. (Turn off subtotals and totals to make the table neater, and change the layout to Tabular to see the field names.)
To create the top right table, put App into the Data field instead.
To create the bottom tables, add the fields in the opposite order.
Note that if you have more details about either personas or apps that you want to record, they should be stored in separate tables. This is now getting into the realm of designing a relational database. Look for references on database design for more information.

RDLC Detail pairs

in and RDLC, on a table each row of info is displayed as two RDLC details rows.
ie
Bob 1234 bobo st 512-512-5122
Jones Austin Tx, 78660 512-512-5133
but when paginating the report, the data pairs get split, with "bob" on one page and "Jones" on another.
Is there any way to force the RDLC Generator to keep these pairs on the same page?
Thanks,
Eric-
Go to Tablix properties
select General
select Page break option
Mark Keep together on one page if possible

AX report: off by one error with joined datasources

We want to build a report in Microsoft Dynamics AX 2009 to show all employees that worked on a production order.
Into the datasources for this report we drag-n-dropped the
ProdTable (pt) which is inner joined by ProdID and DataAreaID to the
ProdJournalRoute (pjr) which is inner joined by EmplID and DataAreaID to the
EmplTable (et) where we look up the employee's name via the name() method.
This report yields some funny output:
pjr.TransDate pjr.EmplID et.EmplID et.name()
2010-07-20 05820
2010-07-20 05820 05820 Doe, John
2010-07-20 05820 05820 Doe, John
2010-07-21 00341 05820 Doe, John
2010-07-21 00007 00341 Snow, Jon
... ... ... ...
(Columns and rows snipped)
See? Somewhere in the join between ProdJournalRoute and EmplTable the EmplID gains a one line offset.
Now I could of course simply copy the name() method from the EmplTable to the ProdJournalRoute table and drop the EmplTable join altogether, but I'm afraid this only postpones the problem: what can I do to get my join to work? Should I use a handcrafted query and use this as datasource for the report?
(PS: could perhaps somebody with the necessary user rights clean up all these
[[[microsoft] dynamics] AX] tags? Thank you!)
Check the relation between the tables ProdJournalRoute and EmplTable.
Set ProdJournalRoute.relations to Yes or add the relations manually.
Got it working.
I'm a little reluctant to admit that the solution was simple: when, out of clues, I rebuild the whole thing from scratch, I added all my ProdJournalRoute fields and EmplTable fields to the EmplTable_Body of the design instead of the ProdJournalRoute_Body like I did the first time around, and that made all the difference.
I still don't quite see how and where a report links the data it displays. I would think that the query should be executed as a whole, joining all the tables involved so that you simply can't get this kind of data discrepancy between tables, but there it is: a datasource <DS> is only refreshed in the <DS>_Body of the design. Using this datasource in the design body of a datasource that is joined further up the query gets weird results: either it is uninitialised, or it shows old data that it got from a join to a prior record.
Thank you again for your thoughts, Mr Kjeldsen.
It seems to me the tables aren't actually joined in the query, but the abstraction level creating the underlying queries are running first a single select on the outmost table, then running a query for the "joined" tables. That might explain why the first row has no data from the EmplTable. My guess is the query to the EmplTable didn't return the data quick enough for the framework. Take a look at the FirstFast property of the datasource and also what it does at MSDN: http://msdn.microsoft.com/en-us/library/aa842737(AX.10).aspx
I might be wrong, though. The only way to really know, is to try snitch the SQL run at the database.