I am trying to figure out how to aggregate the number of hours a person worked that is repeated by each fringe code that they have.
The data looks like this
Company Code Employee Code Employee Name Hours Fringe Code Fringe Amount
030 12345 Joe Blow 8 VAC 10.00
030 12345 Joe Blow 8 DUE 5.00
030 12345 Joe Blow 8 INTDUE 2.00
030 54698 Alan Low 8 VAC 10.00
030 54698 Alan Low 8 DUE 5.00
030 54698 Alan Low 8 INTDUE 2.00
Now the total number of hours should by 16. In the report I have grouped the following fields Company Code, Employee Code, Employee Name, Hours so that they only appear once (not sure how to show that).
I tried to do the following
Sum(FIRST(Fields!Hours.Value, "Employee_Name") , "Company_Code")
but I get an error saying that the value is using a First aggregate in an outer aggregate and that they cannot be specified as nested aggregates.
Any ideas?
I am not sure what you want so I guess a possible result scenario.
I 've reproduced the providing input table.
Using this tablix data settings:
Add this code to the report. This function will flag those rows that must be summed.
Dim groups As System.Collections.Hashtable
Function MyFunc(ByVal group As Object) As integer
dim flag as integer
If (groups Is Nothing) Then
groups = New System.Collections.Hashtable
End If
If (Not groups.Contains(group)) Then
flag = 1
groups.Add(group, nothing)
else
flag = 0
End If
MyFunc = flag
End Function
And this expression in the tablix textbox you want to put the sum.
=sum(val(iif(Code.MyFunc(Fields!Employee_Code.Value) = 1, Fields!Hours.Value, 0)))
You'll get this preview
Let me know if this was helpful.
Well I had issues with some of the above suggestions but I figured out how to solve the problem.
I used the following equation:
=SUM(MAX(Fields!Regular_Hours.Value, "Employee_Code","Company_Code")
Thus I used the MAX function to get only one occurrence per Employee Code and then did a sum of that one occurrence over the Company Code grouping.
Thanks for your guys help!
Related
Activity
Employee
Week of May 17
Week of May 24
Inbox
Alice
3
4
Inbox
Jane
5
8
Alpha Project
Alice
10
3
Beta Project
Francis
7
5
Chi Project
Jane
4
3
I've attempted to use conditional formatting, arrays & Vlookups and unable to cleanly get the following end result.
The End result is to flag anybody working > 10 hours for a given week.
Table is above.
End result should change the color of a cell titled "Alice" outside of this table because Alice worked 13 hours during Week of May 17.
End result should change the color of a cell titled "Jane" outside of this table because Jane worked 11 hours during Week of May 24.
Francis worked 10 hours or below, so no action is needed.
Any help on this is much appreciated --
Create a condition with the following formula:
=SUMIF(B2:B6,F2,C2:C6)>10
Where B2:B6 is the column of Employee names, F2 is the cell you want coloured, and C2:C6 is the column of the May 17th week
I'm quite new to BI designing DB, and here some point I do not understand well.
I'm trying to import french census data, where I got population for each city. For each city, I have population with different age classification, that can't really relate with each other.
For instance, let's say that one classification is 00 to 20 years old, 21 to 59, and 60+
And the other is way more precise : 00 to 02, 03 to 05, etc. but the bounds are never the same as the first one classification : I don't have 15 to 20, but 18 to 22, for example.
So those 2 classifications are incompatible. How can I use them in my fact table ? Should I use 2 fact tables and 2 cubes ? Should I use one fact table, and 2 dimensions for 1 cube ? But in this case, I will have double counted facts when I'll sum to have total population for a city, won't I ?
This is national census data, and national classifications, so changing that or estimating population to mix those classifications is not an option. And to be clear, one row doesn't relate to one person, but to one city. My facts are not individuals but cities' populations.
So this table is like :
Line 1 : One city - one amount of population - one code for dim age (ex. 00 to 19 yo) of this population - code (m/f) for the dim gender of that population - date of the census
Line 2 : Same city - one amount of population - one code for dim age (ex. 20 to 34) of this population - code (m/f) for the dim gender - date of the census
And so it goes for a lot of cities, both gender, and multiple years.
Same
I hope this question is clear enough, as english is not my native language and as I'm quite new in DB and BI !
Thanks for helping me with that.
One possible solution using a single fact table and two dimensions for the age ranges:
1 - Categorical range based on the broadest census, for example:
Young 0-20
Adult 21-59
Senior 60+
You could then link the other census to this dimension with approximate values, for example 18-22 could be Young.
2 -Original age range. This dimension could be used for precise age ranges when you report on a single city, it can also help you evaluate the impact of the overlapping bounds (e.g. how many rows are in the young / 18-22 range?)
you can crate one dimention as below
young 1-20
adult 21-59
senior 60+
Classification is
young city 1 : 1-20
young city 2 : 4-23
id field1 field2 field3 field4 .......
1 1 year young_city_1 other .......
2 2 year young_city_1 other .......
3 3 year young_city_1 other .......
4 4 year young_city_1 young_city_2 .......
Now you can report from any item and with any division
i hope it is help you
Spreadsheet column setup:
A:Name B:Hours C:Client D:Invoice# E:Date
Joe 8 Acme 123 8/21/18
Bill 12 Zorg 456 8/19/18
John 9 Acme 123 8/21/18
Ben 15 Acme 987 8/5/18
I want to count the number of jobs we did for a client for the month.
Each individual job is denoted by the invoice number. A job may have multiple people on it so the same invoice number will be duplicated in column D.
I'd like exclude those duplicates so I get a true count of jobs for a particular client regardless of how many people were actually on the job.
Using the example above, if I ask for total number of "Acme" jobs this month, I need the output to read 2 (since invoice 123 had a couple guys on it) not 3 due to it not excluding the duplicate invoice number.
Nothing I try or search on the internet like function CountIf quite meets my unique parameters.
Please advise, Thank you.
Ok, from the title it seems to be impossible to understand, I'll try to be as clear as possible.
Basically, I have a table, let's call it 'records'. In this table I have some products, of which I store 'id', 'codex' (which is a unique identifier for a certain product in the whole database), 'price' and 'situation'. This last one is a string which tells me wether the product has just entered the store (in that case it is set to 'IN'), or it has already been sold ('OUT' in this case).
The database was not created by us, I HAVE to work with that although it is horribly structured... The guy who originally projected the database decided to register when a product's situation passes from 'IN' to 'OUT' in the following way: instead of UPDATEing the corresponding value in the table, he used to take the row of data with 'IN' as situation, and to DUPLICATE it setting, that time, 'OUT' as situation.
Just to sum up: if a product has not been sold yet, it will have one row of dedicated data; otherwise those rows will be two, identical except for the 'situation' field.
What I need to do is: select a product if (and ONLY if) there is no duplicate for it. Basically, I can (and should) look for a 'codex', and if I my Count(codex) ends up being >1, I do not select the row.
I hope the explanation of the process is clear enough...
I tryed many alternative (no, SELECT DISTINCT is not a solution): des anyone have an idea of how to do that? Because really, none of us three could come up with a good solution!
Here is the schema for the table, I hope it is sufficiently clear, and if not do not hesitate asking for more details.
Just as a reminder: the project is in (sigh...) VB.net, the database is in Microsoft Access (mdb).
I could not find a solution on StackOverFlow, I hope this is not a duplicate question! Thanks in advance for the help.
id codex price situation
1 1 2.50 IN
2 1 2.50 OUT
3 2 3.45 IN
4 3 21.50 IN
5 2 3.45 OUT
6 4 1.50 IN
To check if I understand what your problem is... In your example table you just want to get the lines with ID 4 a 6, right?
If is that what you want, and If you want only the not sold ones try this command
SELECT
*
FROM
records
WHERE
codex
not in
(
SELECT
codex
FROM
records
WHERE
situation ='OUT'
)
I want something strange here. I've table names as EMP_INFO which contains few details of an employee (i.e. Name,Designation, JOIN_FROM, JOIN_TO). I am trying to figure out term for each employee on yearly basis. I've below types of data
EMP_ID EMP_DESIG JOIN_FROM JOIN_TO Query Result
1 Supervisor 01-05-11 30-04-13 Should Display
2 Supervisor 15-06-10 31-12-12 Should Display
3 Jobar 01-01-12 31-12-13 Should Display
4 SR Superior 01-12-11 31-12-15 Should Display
5 Supervisor 01-05-11 31-12-13 Should Display
6 Supervisor 01-05-11 31-12-13 Should Display
7 Supervisor 01-05-11 31-12-13 Should Display
8 Supervisor 01-02-12 15-06-13 Should Display
9 SR Superior 16-03-10 18-11-11 Should Display
10 SR Superior 16-06-05 18-11-11 Should Display
11 Jobar 30-11-11 31-12-13 Should Display
12 Superior 02-02-05 31-12-20 Should Display
13 Jobar 30-11-11 31-12-13 Should Display
14 Jobar 30-11-09 31-12-10 Should Not Display
Basically what i need is I have date range in my report and let's say From: "01-Jun-11" To "31-Dec-13". From above record set report should retrieve all records as all records contains this both dates.
I have tried by using BETWEEN syntax but i believe it will not work.
If anyone can help me in this than it would be appreciated.
Thanks in Advance.. And one more thing if this details is not enough to understand than let me know i will add more in details.
Modified
Query which I tried
SELECT EI.*
FROM EMP_INFO EI,
(SELECT
TO_DATE('01-JUN-2011','DD-MON-YYYY') A,
TO_DATE('31-DEC-2013','DD-MON-YYYY') B FROM DUAL) X
WHERE
(EI.JOIN_FROM IS NOT NULL AND EI.JOIN_TO IS NOT NULL)
AND (
X.A BETWEEN EI.JOIN_FROM AND EI.JOIN_TO
AND X.B BETWEEN EI.JOIN_FROM AND EI.JOIN_TO
OR (EI.JOIN_FROM >= X.B AND EI.JOIN_TO <=X.A) )
Modified Added column (Query Result) on above table which contains result for each record.
So you simply want all records where the join time is in the given time range? That would be:
SELECT *
FROM EMP_INFO
WHERE JOIN_FROM BETWEEN
TO_DATE('01-JUN-2011','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN') AND
TO_DATE('31-DEC-2013','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN')
AND JOIN_TO BETWEEN
TO_DATE('01-JUN-2011','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN') AND
TO_DATE('31-DEC-2013','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN');
EDIT: Sorry, I got it now. You are looking for all time ranges that overlap with the given range. That would be: ranges that start before and end within, ranges that start before and end after, ranges that start within and end within and ranges that start within and end after. Another way to express this is: Either the given time range start is within the other time range or the other time range start is within the given time range. Here is the according statement:
SELECT *
FROM EMP_INFO
WHERE JOIN_FROM BETWEEN
TO_DATE('01-JUN-2011','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN') AND
TO_DATE('31-DEC-2013','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN')
OR TO_DATE('01-JUN-2011','DD-MON-YYYY', 'NLS_DATE_LANGUAGE=AMERICAN')
BETWEEN JOIN_FROM AND JOIN_TO;
And here is the SQL fiddle: http://sqlfiddle.com/#!4/b58b3/3
Convert to same format and compare. There may be a time component in the dates stored in database. Previous answer was wrong.