My data view is look like below:
To do the SUM of salary group by employee id I have created 2 measure as below:
Measure = MAXX(DISTINCT(Employee1[EmployeeId]),MAX(Employee1[Salary]))
SumSalary = SUMX(DISTINCT(Employee1[Salary]),[Measure])
I tried as below but it does not work. Showing wrong values in Power BI.
SumSalary = SUMX(DISTINCT(Employee1[Salary]),MAXX(DISTINCT(Employee1[EmployeeId]),MAX(Employee1[Salary])))
Is there any other way to combine those measures?
I would try something along these lines:
TotalSalary = SUMX(
SUMMARIZE(Employee1,
Employee1[EmployeeId],
"EmployeeSalary", MAX(Employee1[Salary])),
[EmployeeSalary])
This first groups them by EmployeeId, taking the maximum salary for that ID, and then sums the salaries for each employee.
Related
im looking for a query to fill this condition:
That currently gives us the number of BACs at the entity (which is something we need). The database assigns the BAC IDs consecutively within each accounting entity. So we need to add one more field to the query showing the current highest BAC ID at the entity. And once we have that, just filter the results down to anyplace the number of records doesn't equal the highest ID.
My current query:
select accounting_entity_id, count(bac_id)
from dc.pl_bac_information
group by accounting_entity_id
having count(bac_id) > 1;
Use analytic functions for this:
select bi.*
from (select bi.*, max(bac_id) over (partition by accounting_entity_id) as max_bac_id
from dc.pl_bac_information bi
) bi
where bac_id = max_bac_id;
This assumes you are using Oracle.
SELECT ACCOUNTING_ENTITY_ID
FROM DC.PL_BAC_INFORMATION
HAVING COUNT(BAC_ID) > 1 AND COUNT(BAC_ID) != MAX(BAC_ID)
GROUP BY ACCOUNTING_ENTITY_ID;
I'm trying to calculate training hours for a list of three departments but I'm not doing the query quite right. The column with the amount of hours is called tEmpCourseDetail.AuthRelTime (AuthorizedReleaseTime). But the below gives me four separate rows. What I want is it to calculate the values in all four rows.
SELECT SUM(AuthRelTime) AS trainingHours
FROM tEmpCourseAssoc
JOIN tEmpCourseDetail ON tEmpCourseAssoc.ECAssocID = tEmpCourseDetail.ECAssocID
WHERE AccountNumber IN ('760413','760416','767601')
GROUP BY AuthRelTime
What I want is it to return these added up. Which would be 15.
Is the group by needed at all? Try taking it out?
i.e.
SELECT SUM(AuthRelTime) AS trainingHours
FROM tEmpCourseAssoc
INNER JOIN tEmpCourseDetail ON tEmpCourseDetail.ECAssocID = tEmpCourseAssoc.ECAssocID
WHERE AccountNumber IN ('760413','760416','767601')
I have seen some close answers and I have been trying to adapt them to Access 2013, but I can't seem to get it to work. I have two queries:
First query returns
original_staff_data
Month
Year
staff_uid
staff_abbrev
employee_name
staff_salary
It pulls this from tables staff, and salary_by_month and employee_name and number_of_days_at_spec_building (this records where they check in when they work)
transaction_data_by_staff.total
Month
Year
staff_uid
total_revenue
totat_profit
this also pulls information from staff, but sums up over multiple dates in a transaction table creating a cumulative value for each staff_uid so I can't combine the two queries directly.
My problem is I want to create a query that brings results from both. However, not all staff members in Q1 will be in Q2 every day/week/month (vacations, etc) and since I want to ultimately create a final results:
Final_Result
Month
Year
staff_uid
staff_abbrev
employee_name
staff_salary
total_revenue
total_profit
The SQL:
SELECT
original_staff_data.*
, transaction_data_by_staff.total_rev
, transaction_data_by_staff.total_profit
FROM transaction_data_by_staff
RIGHT JOIN original_staff_data
ON (
transaction_data_by_staff.year = original_staff_data.year
AND transaction_data_by_staff.month = original_staff_data.month
) WHERE transaction_data_by_staff.[staff_uid] = [original_staff_data].[staff_uid];
I would like it if there is no revenue or profit that month from that employee, it makes those values 0. I have tried join (specifically RIGHT join with Q1 as the RIGHT join) and it doesn't seem to work, I still only get the subset. There are originally in the original_staff_data query 750 entries so therefore there should be in the final query 750 entries, I am only getting 252, which is the total in transaction_data_by_staff. Any clue on how the ACCESS 2013 SQL should look?
Thanks
Jon
Move the link by stuff_uid to the ON clause, like this:
SELECT original_staff_data.*, transaction_data_by_staff.total_rev, transaction_data_by_staff.total_profit
FROM transaction_data_by_staff RIGHT JOIN original_staff_data ON (transaction_data_by_staff.year = original_staff_data.year) AND (transaction_data_by_staff.month = original_staff_data.month)
AND (((transaction_data_by_staff.[staff_uid])=[original_staff_data].[staff_uid]));
I would like to show the number of rows of two columns which belonging to two tables. However, the result is not I expected. I am really confused about that. Could you please advice? Thanks.
SELECT COUNT(TABLE1.INTEREST) FROM INCOME; // RESULT = 10
SELECT COUNT(TABLE2.LOAN) FROM EXPEND; //RESULT = 10
SELECT COUNT(TABLE1.INTEREST), COUNT(TABLE2.LOAN) FROM INCOME, EXPEND; //RESULT = 100
Why the result is "100|100" if I execute the third SQL command? I expect the result is "10|10".
A cartesian product is performed in your last query.
It's because you are joining every row of INCOME onto every row of EXPEND (called a cartesian product)
Instead of doing FROM INCOME, EXPEND you need to do something like
FROM INCOME
JOIN EXPEND
ON Income.SomeColumn = Expend.SomeColumn
or add a where clause to your current query:
FROM INCOME, EXPEND
WHERE Income.SomeColumn = Expend.SomeColumn
I have two tables in my setup. One with sales persons and there income. Each sales person only know their total income. For this particular income period, they are asked to give an estimate of their income on either private, small business or large business customers. This information is entered in the second table.
Income
=================
SalesPerson
Income
Distribution
=============================
SalesPerson
CustomerType
Weight
Now, my query would look something like this:
SELECT
Income.SalesPerson,
Distribution.CustomerType,
Income.Income * Distribution.Weight as DistributedIncome
FROM
Income INNER JOIN Distribution ON
Income.SalesPerson = Distribution.SalesPerson
How would I enforce, that the SUM(Weight) = 1 for each SalesPerson in Distribution?
Normalize by the sum, according to the same criteria.
SELECT
Income.SalesPerson,
Distribution.CustomerType,
Income.Income * Distribution.Weight/(
select sum(d.weight)
from distribution d
inner join income i on i.salesperson = d.salesperson
)
as DistributedIncome
FROM
Income INNER JOIN Distribution ON
Income.SalesPerson = Distribution.SalesPerson
If somehow want to select unmodified weights that sum to 1 then I believe you've got a case of the subset sum problem and you are probably not going to be able to solve this with an SQL query.