SSRS grouping all but one field - grouping

I have a query that all the fields are the same except for one. I want to group my SSRS report so that it has "blanks" for all the duplicated fields and only show the "different" one WHEN there is a "duplicate" record.
For instance:
Case Number PersonID Narrative
123 1 xxx
345 3
456 9 ABCD
KFL
So record 1 has a narrative and only one record. Record 2 has no narrative. Record 3 & 4 are the same case, same person, two different narratives.
I thought by grouping by all the other fields that I would achieve these results but that is not working, I still get the 456 and 9 on my 4th record when I have grouped by the other fields.
How can I get just the narrative to display when all the other fields in that record match the previous record?
Thanks,
Leslie

You can see my answer for:
How to get only one value in SSRS?
You have similar situation. You need to use expression for first 2 columns:
=IIF(Fields!CaseNumber.Value = Previous(Fields!CaseNumber.Value), "", Fields!CaseNumber.Value)
=IIF(Fields!PersonID.Value = Previous(Fields!PersonID.Value), "", Fields!PersonID.Value)
This will hide all repeating "Case Number" and "PersonID".
Don't forget to replace "CaseNumber" and "PersonID" with proper column names in DataSet.

Related

Django ORM Count group and subgroup

In my django project i had a table with a column named 'key_id'. Until today i had to group different values of this values, count it and display the largest result.
I did this:
maxpar = temp_test_keywords.objects.filter(main_id=test_id).values('key_id').annotate(total=Count('key_id')).order_by('-total').first()
maxMax = maxpar['total']
all done.
Today, we deceide to add another field to table, 'key_group'(could be 1,2,3,4) and now i have to use the same query for group and count max key_id field but related also for key_group.
For example before if in my table there was 5 record with key_id=187 and 3 with 112 my query had to return 5, now if for that 5 records 4 contain 'key_group=1' and one = 2 query have to return 4
Hope i was clear
Thanks in advance
Luke

Look up function inside IF condition visibility - SSRS

I have a SSRS report with one tablix and i want to hide the tablix based on a condition. I am using two datasets there. The tablix contains dataset1 records. I want to check the dataset2 with Pno and if then only need to display that Pno in tablix.
Dataset1
Pno Group
1 A
2 S
3 D
4 F
Dataset2
Pno Supply Demand Group
1 A
3 D
5 B
6 R
Now I want to display only
Pno Group
1 A
3 D
I am using the following condition.
=IIF(Lookup(Fields!Group.Value, Fields!Pno.Value, Fields!Pno.value, "Dataset2"), True, False)
But it doesn't filter the records. Can anyone help me to solve this?
Thanks in advance...
I think that you may just have your Lookup parameters mixed up. Try this:
=IIF(Lookup(Fields!Pno.Value, Fields!Pno.value, Fields!Group.Value, "Dataset2"), True, False)
One step further:
=IIF(Lookup(Fields!Pno.Value, Fields!Pno.value, Fields!Group.Value, "Dataset2") <> "", True, False)
In a Lookup, the first 2 parameters are the fields that need to match, the third is the value being returned, the fourth is the dataset being queried.
Try using this expression in for hidden in the Row visibility window:
=IIF(ISNOTHING(ReportItems!Group.Value),True,False)
ReportTems!Group is the name of the cell where you are using the Lookup function, replace Group by the actual name of the cell:
=Lookup(Fields!Group.Value, Fields!Pno.Value, Fields!Pno.value, "Dataset2")
If your cell has a different name select the cell and press F4 to see the properties window, look for the name property.
It will produce:
Let me know if this helps.

Many-to-Many field find record

I want to query the database and get the data of against id which have highest occurence in the database table.
story table
id story_name
1 this is one
2 this is two
story_story_table
id story_id
1 1
2 1
3 1
4 2
5 3
now id 1 have highest occurence. first find highest occurence then get data against this id. using django
You can find the highest occurrence using django's ORM built in API.
unique_fields = ['story_id','story_name_id']
duplicates = (Model.objects.values(*unique_fields)
.annotate(max_id=models.Max('id'),
count_id=models.Count('id'))
.filter(count_id__gt=1)
.order_by())
This will gives repeated records as per given fields and to highest occurrence you can simply use len(duplicates)
Edited:
highest_occured = (Model.objects.values(*unique_fields)
.annotate(max_id=models.Max('id'),
count_id=models.Count('id'))
.filter(count_id=models.Max(count_id))
.order_by())
I hope this will be help full. :)

How to parse through a column in Pig to create additional columns

New Apache Pig user here. I basically have data in a format and need to split this into 6 columns to create my desired schema and then load into Pig for my existing script to run.
Sorry if the format below is untidy, i cant upload a picture due to reputation score.
Existing format has 3 columns
User-Equipment values::key:bytearray values:value:bytearray
user1-mobile 20130306-AC 9
user1-mobile 20130306-AT 21
user2-laptop 20130306-BC 0
Required format:
User Equipment Date Type "Count or Time" Value
user1 mobile 20130306 A C 9
user1 mobile 20130306 A T 21
Any suggestions on how to ge this done? IS there a regex I need to write?
The tricky thing here is all the columns have a delimiter (-) between them except "Type" and column "C or T"
If you don't have a common delimiter I can think of two possibilities:
You could implement your own LoadFunc as explained here: http://ofps.oreilly.com/titles/9781449302641/load_and_store_funcs.html
You could use REGEX_EXTRACT_ALL as explained here: Apache Pig: Extra query parameters from web log
Here you go for 2.:
A = LOAD 'abc.txt' AS (line:CHARARRAY);
B = FOREACH A GENERATE FLATTEN(REGEX_EXTRACT_ALL(line, '^(.+?)\\-(.+?)\\s(.+?)\\-(.)(.)\\s(.+)$')) AS (User:CHARARRAY,Equipment:CHARARRAY,Date:CHARARRAY,Type:CHARARRAY,CountorTime:CHARARRAY,Value:CHARARRAY);

Rails 4 + MongoDB + Search query LIKE does not give correct output

In Rails, I am trying to fetch data from mongodb using LIKE query by providing regular expression but even though not getting the correct output.
Model : User
_id, name, display_name, age, address, nick_name
a1, Johny, Johny K, 12, New York, John
b1, James, James Waltor, 15, New York, James
c1, Joshua, Joshua T, 13, California, Josh
Now I have 3 set of records.
Query 1 : Search User having 'Jo' as keyword in initial name
User.where(name: /^jo/i)
Output - Only One record - instead of two.
Query 2 :- Match the text with all column values
User.where($where: /^jo/i)
Not getting the proper output.
Ok on the Query 1, can you output the documents. I believe one of your records in 'name' has a character in front of it such as white space. I just run the same query locally and it pulled multiple records back.
Try this:
User.where(name/(.*)jo(.*)/i).count and see what that returns. It should match 2. If that works, then you'll need to look at what is incorrect with the store value.
On Query 2, where have you seen this syntax. The $where is expecting a string of a js function to execute to match records. In your case to match any field within the document with an expression you would need to do a recursive function across each field in each document.
For Query 2 to match against all fields
One solution, although inefficient, is to do it within the Rails app instead of Mongodb query.
e.g.
User.all.select do | user | user.attributes.values.grep(/^jo/i).any? end