MDX: Get parent of leaves of ragged hierarchy - reporting-services

I working on report to display each country and how many reps and sales managers in this country for the measure of reps count I created by found the lowest level and by this query.
iif(IsLeaf([FF Hierarchy].[FF Hierarchy].currentmember),[Measures].[#Employees],null)
The problem is Sales manager isn't known level we can know this member is Sales manager when he is parent of rep in other meaning parent of the leaf
I don't know how get this level.
This is my code:
with member [#Reps1] as
iif(IsLeaf([FF Hierarchy].[FF Hierarchy].currentmember),[Measures].[#Employees],null)
member [# of rep1] as
SUM(DESCENDANTS([FF Hierarchy].[FF Hierarchy].currentmember,0,SELF_AND_AFTER),[Measures].[#Reps1])
SELECT NON EMPTY { [Measures].[# of rep1] } ON COLUMNS,
NON EMPTY {
([FF Hierarchy].[Business Unit].[Business Unit].MEMBERS )
* Descendants([FF Hierarchy].[FF Hierarchy],1,self)
} ON ROWS
FROM [FFE Cube]

Related

sum values about 1:n eloquent

I have the following model: https://imgur.com/a/Ib9QWco All tables are 1:n
regional -> coordination -> company -> team -> cell -> payment_book->payment
the payment table takes care of all payments, inside it I have the payment.pay column which is a boolean that defines if it was paid or not.
I would like to make a query from the team table that would return the total of each cell that was paid and unpaid in the same query.
and when the query is from company, it will return the total of each team, the paid and unpaid total.
and so on until you reach regional.
I had done it in a way using foreach to add the values, but it didn't return the total individually for each one, but the total of all added together.

How to write SSRS 2017 expression for calculating percentages when report contains Row Groups level hierarchy data

I'm trying to show monthly data for products. A month can have any number of products from A to Z depends on availability of products for that month.
For example, January 2020 has products A, B, and C.
Total is sum(amount) for these products.
I have taken Column Groups hierarchy as MonthYear and Product; Row Groups hierarchy as City, State, Region, and Country.
I'm able to show Total column at State, Region,and Country level by adding up at group level.
But I'm facing difficulty in showing Product% column figures especially at State, Region,and Country level.
For Product%, I'm trying to write something like sum(amount)/[sum(amount) for ALL Products].
Could you please help me in writing SSRS expression for achieving Product% figures at State, Region,and Country level.
Assuming you have a row group called 'groupCity' then this should work.
=SUM(Fieldsamount.Value) / SUM(Fields!amount.Value, "groupCity")
You will need to change the expression to match the rowgroup name for each additional instance that you need it (so probably state, region and country)

How to create a parent group totals based on different child group

I'm not sure if I'm phrasing this correctly...
I need help splitting a total to have multi-rows/columns inside a total;
or another way to say this is, I need to have a parent group total with based on different child group.
Please see the picture below:
I am using matrix element for my stepped report. I have 4 tiers of groups on the Y-axis, and 3 tiers of groups on X-axis. On the y-axis, I have created totals for my tier 2 - Products (Linked/non-par) and totals for my tier 3 - products (A / B).
However, for the tier 3 - products (A / B) total, I need to split that total into total-A and total-B, so that the accumulative total values (66800) would be split into the sum of product A and sum of products B.
I'd like to do this without using expressions if possible. But if there are no solution, I'm open to Expression or changing dataset w/ T-SQL (if necessary).
Any ideas?!

ssis duplicate rows and script componenet

So, not sure how to explain this but here goes. I am trying to translate a table of commissions earned. Some of the records have the same invoice and item meaning multiple people earned commissions on that product. I want to merge those records so I only have one record per product per invoice. Basically, like a pyramid scheme, salespeople make commissions on sales and depending on what level they are at, (1,2,3,4) all salespeople above them get a commission as well. So I need to find records where invoice and item are the same,
pull data from each of those records and then output only one record with that data.
I am pretty sure a script component is the way to go but I am not sure how to pull multiple rows of data in to check for duplicate invoice and item, also keeping some of the data for each row to output together.
Let me know if you have any questions, I know I didn't word that the best.
The source table looks like this
COMMISSION Table
SalespersonID - the person getting the commission
InvoiceID - ID of invoice
ItemID - ID of specific lineitem on invoice
ProductID - ID of product sold
Sales_Amt - total for that lineitem
Salesperson Downlevel ID - ID of salesperson below SalespersonID if exists
Commission Rate - percentage Salesperson receives
Commission Total - amt salesperson receives
There are some other columns but these are the important ones.
I am translating this into a table that looks like this
New COMMISSION Table
CommissionId - Primary key for commission table
CommissionPayable - amt salesperson gets
CommissionPayableUpline1 - amt salespersonUpline1 gets
CommissionPayableUpline2 - amt salespersonUpline2 gets
CommissionPayableUpline3 - amt salespersonUpline3 gets
CommissionRate - percent salesperson gets of amount
CommissionRateUpline1 - percent salesperson upline1 gets
CommissionRateUpline2 - percent salesperson upline2 gets
CommissionRateUpline3 - percent salesperson upline3 gets
SalespersonId - Id of salesperson
SalespersonUpline1 - ID of salesperson upline1
SalespersonUpline2 - ID of salesperson upline2
salespersonUpline3 - ID of salesperson upline3
So you see we can have up to four levels of salespeople. Most of our salespeople are only 1 to 2 levels but we do have a few 3 levels deep and none currently that are four levels deep. The way it is stored in the old database is confusing and not very efficient.
I want to find rows with duplicate invoice and item ids, grab the salespeople, and down level salespeople as well as commission rates and amounts for each, then insert all that into one row in new system.
Well I finally got this figured out by using the ssis script component and then doing some fancy sorting and creating new records on output.

Microsoft Access 2010 - Filtering by a caculated field in a query-based report

Ok, here's the condensed form. I have three main tables to draw data from:
StudentData - PK is the student's ID Number. Contains contact info, their current status ('00' for none, 'P' for Probation, 'S' for Suspension), and cumulative gpa data.
CourseData - PK is the CRN. Contains just the abbreviated subject and the course number (IE ECON 200)
StudentCourses - PK is an AutoNum. Many-to-Many relationship table between StudentData and CourseData. Also contains stats for the particular student's class (grade, credit hours, etc).
So some sample data would look like:
-
StudentData
ID: 12345678
Name: John Doe; ...[Other contact info]; 00; CumCreditHours: 100; CumCoursePoints: 190
-
CourseData
CRN: 0001; Abbrev: ECON; CourseNumber: 101
CRN: 0002; Abbrev: CSCI; CourseNumber 201
-
StudentCourses
AutoNum: 1
StudentID: 12345678; CRN: 0001; Grade: A-; Credits: 3
AutoNum: 2
StudentID 12345678; CRN: 0002; Grade: B; Credits: 3
-
At this point, this is how I have things set up:
First, a query runs that finds all of the courses a student takes and converts the letter grades into a point value. Another query based on the first sums the point totals and the credit hours. A third query takes those totals and calculates the GPA by dividing their point total by the credit hour total.
Separately, a query runs that calculates the student's cumulative GPA by taking their cumulative points and hours from the StudentData table (again dividing the points by the hours).
Then, another query takes both the semester GPA, cumulative GPA, current status, and cumulative credit hours and calculates the recommended action for the student. So for our example data it would look like:
_
SemesterGPA: 3.33; CumulativeGPA: 1.90; CurrentStatus: 00; CumulativeCreditHours: 100
_
I have the formula to determine their recommended action set up as a series of nested IIF statements that looks like:
IIf([CurrentStatus]="00" And [CumulativeGPA]<2 And [CumulativeCreditHours]>=12 And [CumulativeCreditHours]<=23,"PFY",IIf([CurrentStatus]="00" And [CumulativeGPA]>=1.7 And [CumulativeGPA]<=1.99 And [CumulativeCreditHours]>=24,"P",IIf([CurrentStatus]="00 " And [CumulativeGPA]<2 And [SemesterGPA]<2 And [CumulativeCreditHours]<12,"W",IIf([CurrentStatus]="00" And [CumulativeGPA]>=2 And [CumulativeGPA]<=2.5 And [SemesterGPA]<2 And [CumulativeCreditHours]>=12,"WUP",IIf([CurrentStatus]="00" And [CumulativeGPA]<1.7 And [CumulativeCreditHours]>=24,"SUSP",IIf([CurrentStatus]="P" And [CumulativeGPA]<2 And [SemesterGPA]>=2 And [CumulativeCreditHours]>=12,"CP",IIf([CurrentStatus]="P" And [CumulativeGPA]>=2 And [SemesterGPA]<2 And [CumulativeCreditHours]>=12,"SPCP",IIf([CurrentStatus]="P" And [CumulativeGPA]>=2 And [CumulativeCreditHours]>=12,"RP",IIf([CurrentStatus]="P" And [CumulativeGPA]<2 And [SemesterGPA]<2 And [CumulativeCreditHours]>=12,IIf(IsNull([PriorSuspension]),"S(FD)","D(SD)"),"None")))))))))
For our example, John Doe's recommended action would be 'P' since his current status is 00, he has over 24 cumulative credits, and his cumulative gpa is between 1.7 and 1.99.
Now for the problem: I would like to be able to make a report that can filter by the recommended action. I've detailed the issues I've had previously, but in short, the way I have the reports set up now (with the information being displayed in a sub-report inside a report that is based on the StudentData table to provide the aforementioned queries with the StudentID) doesn't allow me to do this because the field I want to filter by exists in the sub-report and not the main report (and you can't set the filter properties for a sub-report).
Any ideas?
Ok, I've got this to work now. I realized that as I was calculating the semester GPAs that I had grouped the results together by ID at some point during the process. This allowed me to remove the part of the initial query that grabbed the ID number from the form. Since the last query in the process linked everything together by student ID, the individual records held all of the information I needed and everything fell into place after that.
I half expected something simple like this to be the answer to my problem, but I'm still disappointed that it took me this long to figure it out...
Anyway, thanks to anyone who might have been thinking of possible solutions for this problem.