issue trying to use combine value to get a value from a datasource - sql-server

I have a summary report with a multiples dataset used in differents lookup, I know the lookup compare single values only, I need to compare double value in a datasets and return the value, I'm trying to using a combined source in a first parameter of lookup but I'm not sure if it will be work
dataset1
name team value
----------------
john team1 3
john team2 4
mark team1 2
jane team2 1
I want to use lookup for this dataset using name and team together to build a unique key and get the correct value like a
lookup for "john+team1" and get the value 3
Any help or idea???

Would it not be easier to compare the 2 datasets within SQL rather than trying to do it in SSRS? Temp table1 would be name etc
Write one massive query to combine all of the data, that was it's easier/ quicker to use and it can be used in one table

Related

Simple database design - some columns have multiple values

Caveat: very new to database design/modeling, so bear with me :)
I'm trying to design a simple database that stores information about images in an archive. Along with file_name (which is one distinct string), I have fields like genre and starring where each field might contains multiple strings (if an image is associated with multiple genres, and/or if an image has multiple actors in it).
Right now the database is just a single table keyed on file_name, and the fields like starring and genre just have multiple comma-separated values stored. I can query it fine by using wildcards and like and in operators, but I'm wondering if there's a more elegant way to break out the data such that it is easier to use/query. For instance, I'd like to be able to find how many unique actors are represented in the archive, but I don't think that's possible with the current model.
I realize this is a pretty elementary question about data modeling, but any guidance anyone can provide or reading you can direct me to would be greatly appreciated!
Thanks!
You need to create extra tables in order to stick with the normalization. In your situation you need 4 extra tables to represent these n->m relations(2 extra would be enough if the relations were 1->n).
Tables:
image(id, file_name)
genre(id, name)
image_genres(image_id, genre_id)
stars(id, name, ...)
image_stars(image_id, star_id)
And some data in tables:
image table
id
file_name
1
/users/home/song/empire.png
2
/users/home/song/promiscuous.png
genre table
id
name
1
pop
2
blues
3
rock
image_genres table
image_id
genre_id
1
2
1
3
2
1
stars table
id
name
1
Jay-Z
2
Alicia Keys
3
Nelly Furtado
4
Timbaland
image_stars table
image_id
star_id
1
1
1
2
2
3
2
4
For unique actor count in database you can simply run the sql query below
SELECT COUNT(name) FROM stars

Power BI - Show all data from table1 in a visual from two many to many related tables when one other field from table2 on the X-axis

I have a key column in two many to many related table and sample representation of data is -
(attaching sample version of the table to get the point across as there are other numerous columns not contributing to this visual)
table 1 -
table 2 -
I am making a line graph with date on x axis and the value1 and value 2 on y-axis. The value1 is true for all dates. It is basically a standard target value. Now I want all the value1 summed up to show in my visual as value1 and not just the ones for which I have data on those dates. To explain it better I want 1717 on the graph as well like the total in the table in the following image -
visual -
Is there a way to do this in power BI? I tried to make a shared dimension of all unique key as a separate table and connecting both the tables to that table but there is no change in visual due to that.
You can follow these below steps to achieve your required output-
Step-1 Create a custom column in your *table 1 as below-
value_1_sum =
CALCULATE(
SUM(table_2[value1]),
ALL(table_2)
)
Step-2 Configure your line chart as below. Remember, the aggregation for new custom column will be Average as shown in the image
And here below is the final output-
Additional Reference Here below is list of options you will get after right click on the measure name-

How to count the particular values in the field in Google Data Studio

I am trying to create a simple table in Google Data Studio, which fetches data from MySql table. For example,
"Peter
John
Mike
Peter
George
Peter"
The above are the set of values in a field,
Here I have to count the number of "Peter" in the field and display the count.
Is it possible to display the count of particular values from a single field? If so, what function should I apply to get the required output?
I would suggest using a REGEXP_MATCH function to create a new field. Try this:
Create new field called Peter Count and use this formula:
CASE
WHEN REGEXP_MATCH(FIELD_NAME, "Peter") THEN 1
ELSE 0
END
Make sure the new field has a field type of Number and aggregation of SUM
Create a scorecard in your report and select your new field as the metric.
That should add up the occurrences of Peter and ignore other names.

Birt report : How to hide in's and out of the table value in Birt Report

I have a following employee table value as below :
name | cost
john | 1000
john | -1000
john | 5000
when we add the cost column total will be 5000.
I need to print only the 3rd row in BIRT report, since the 1st and 2nd row get cancelled out each other.
I'm stuck at filtering the table for above scenario.
Couldn't you just solve this using SQL like
select name, sum(cost)
from employee
group by name
order by name
?
Or do you just want to exclude two rows if they have exactly the same cost, but with different signs? Note that this is actually something different, take for example the three rows [ john|1, john|2, john|-3 ]? In this case, a pure SQL solution can be achieved using the SQL analytic functions (at least if you are using Oracle).
Elaborate your question. Its not clear if these are columns or rows.
If These are columns:
Create a computed column in your dataset
In Expression builder of that column add/sub values using dataSetRow['col1'] and dataSetRow['col2']
Add only that computed column to your table.
If these are rows
Select rows you don't want to print
Go to properties tab
Find Visibility property and click on it
Check Hide Element option

Is it possible to create an SQL query that displays results like this?

Background
I have a database that hold records of all assets in an office. Each asset have a condition, a category name and an age.
A ConditionID can be;
In use
Spare
In Circulation
CategoryID are;
Phone
PC
Laptop
and Age is just a field called AquiredDate which holds records like;
2009-04-24 15:07:51.257
Example
I've created an example of the inputs of the query to explain better what I need if possible.
NB.
Inputs are in Orange in the above example.
I've split the example into two separate queries.
Count would be the output
Question
Is this type of query and result set possible using SQL alone? And if so where do I start? Would it be easier to use Ms Excel also?
Yes it is possible, for your orange fields you can just e.g.
where CategoryID ='Phone' and ConditionID in ('In use', 'In Circulation')
For the yellow one you could do a datediff of days of accuired date to now and divide it by 365 and floor that value, to get the last one (6+ years category) you need to take the minimum of 5 and the calculated value so you get 0 for all between 0-1 year old etc. until 5 which has everything above 6 years.
When you group by that calculated column and select the additional the count you get what you desire.

Resources