I have an issue when trying to drill through in excel. I have a fact table of employee terminations set up like the following. Each row is a termination.
For the drillthrough function in SSAS I am using ASSP.GetCustomDrilthroughMDX. Basically created a new action in the cube with the following action expression.
'call ASSP.ExecuteDrillthroughAndFixColumns("'
+ ASSP.GetCustomDrillthroughMDX("
[$Employee].[Employee ID]
, [$Employee].[Company Name]
, [$Employee].[Last Name]
, [$Employee].[First Name]
, [$Employee].[Start Date]
, [$Employee].[Last Day Worked]
, [$Employee].[HR Title]
, [$Employee].[Working Title]
, [$Employee].[HR Status]
, [$Employee].[Location ID]
, [$Department].[Department Number]
, [$Department].[Department Name]
, [$Employee].[Supervisor]
, [$Division].[Division Name]
")
+ '")'
The Condition is
[Measures].CurrentMember IS [Measures].[Involuntary] or
[Measures].CurrentMember IS [Measures].[Voluntary]
When I bring the Desired, Undesired, Voluntary, Involuntary and Other measures into a pivot table and try drill into say the Voluntary, I get the detail of the total amount of employees terminated, not just the Voluntary. For example if 6 employees were Voluntary, and 4 were Involuntary, and I drill into the voluntary I don't get the 6 employees, I get all 10 detail rows. I'm hoping I don't have to create a separate measure group for each type of termination. Any ideas?
So I figured this out.
In the Cube Design, I clicked on each measure in the Termination measure group and went to properties. Under properties expand Source. For NullProcessing property, set it to Preserve. This will preserve the null values in the underlying fact table. By default SSAS treats nulls as zero. Hope this helps someone else.
Related
Below is my mock database that I am using. I have four different tables: Tbl_MainDatabase, Tbl_InsuranceCoverage, Tbl_MatterDetail, and Tbl_PaymentProcessing.
What I want -
I want my form to determine the remaining Retention Limit (i.e., Retention Limit for the applicable policy - sum of invoices for the same Claim Number )
According to the mock database, the required answer should be [ $2500 - (300+700+355)] as highlighted for your convenience
What I tried
I used the help of Graphical representation through the following query:
SELECT [Claim Number], Sum([Net Invoice Amount])
FROM [PaymentProcessing]
GROUP BY [Claim Number]
This method works to show me how much I spent per claim number so far in the form of a graph. However I want to display the remaining amount.
Any Help is appreciated :)
I am one month old at using Access. But I am trying my best to learn
Thank you in advance!
SELECT
IC.[Retention Limit]-SUM([Net Invoice Amt]) AS Remaining, MD.[Claim Number], IC.[Retention Limit], IC.InsuranceID
FROM tbl_InsuranceCoverage IC
INNER JOIN tbl_MatterDetail MD ON ic.InsuranceID = MD.Policy
INNER JOIN tbl_PaymentProcessing PP ON MD.MatterDetailID=pp.MatterDetailID AND MD.[Claim Number]=pp.[Claim Number]
GROUP BY MD.[Claim Number], IC.[Retention Limit], IC.InsuranceID
See if this works. Havent tested it but seems simple. You can remove the extra columns, but this will hlep you understand joins a bit
For All the New users The above code by #Doug Coats works perfectly.
Make Sure All the Foreign Key and Primary Keys is linked in the Relationship Property. ( One of the way To do this in the Query is - Right click on the Query and select Design View --> Right click again on the grey space and Select Show all Tables Now Drag your Primary Key of the table and drop at the foreign Key on the other table --> This will create a relationship between both for the Query Purpose.
This will also Prevent Data from Duplication in the query then use a similar code as described by Doug Coats in the above comment in the SQL View
SELECT [Insurance Coverage].[Retention Unit]-Sum([Net Invoice Amount]) AS Remaining, [Matter Detail].[Claim Number], [Insurance Coverage].[Retention Unit], [Matter Detail].Policy
FROM (([Main Database] INNER JOIN [Matter Detail] ON [Main Database].[Database ID] = [Matter Detail].[Short Name]) INNER JOIN [Payment Processing] ON ([Matter Detail].[Matter Detail ID] = [Payment Processing].[Matter Detail ID]) AND ([Main Database].[Database ID] = [Payment Processing].[Short Name])) INNER JOIN [Insurance Coverage] ON [Matter Detail].Policy = [Insurance Coverage].[Insurance ID]
GROUP BY [Matter Detail].[Claim Number], [Insurance Coverage].[Retention Unit], [Matter Detail].Policy;
You can then display this query in the form - I am still evaluating best way to display this query probably in a Combo Box (Not sure if any other controls has a row source)
Thank you
I have a query where I'm calculating Days of Therapy for medications. I want to have 0 values to show for months that have no data. Currently the query returns no record if the Sum is 0. Can't seem to figure this out. See the Query Below:
If I were to comment out identifiers related to the DOT_ALL table along with the Where Clause I get 60 rows, 1 for each month for the past 5 years. However, otherwise i get only 57 for the drug in the Where Clause since there are not DOTs for Aug 2016, April 2016 and Jan 2015.
Thanks in advance.
----------------------------------------------------------------------------
SELECT
AMS.[Medication Name]
, SUM(AMS.DOT) AS DOT
, PD.[Patient Days]
, PD.[Month_Name]
, PD.[Fiscal_Month]
, PD.[Accounting_Year]
, PD.[Year]
FROM
DW_PROD.dbo.Patient_Days_By_Month PD
Left JOIN [DW_PROD].[dbo].[DOTS_All] AMS ON (PD.Month_Name = AMS.Month AND PD.Year = AMS.Year)
WHERE
[Medication Name] = 'CEFUROXIME'
GROUP BY
AMS.[Medication Name]
, PD.[Patient Days]
, PD.[Month_Name]
, PD.[Fiscal_Month]
, PD.[Accounting_Year]
, PD.[Year]
ORDER BY
ACCOUNTING_YEAR
,FISCAL_MONTH
This may be the cheapest solution, under the assumption that Patient_Days_By_Month is already some kind of calendar.
SELECT
'CEFUROXIME' AS [Medication Name],
SUM(AMS.DOT) AS DOT,
PD.[Patient Days],
PD.[Month_Name],
PD.[Fiscal_Month],
PD.[Accounting_Year],
PD.[Year]
FROM DW_PROD.dbo.Patient_Days_By_Month PD
LEFT JOIN [DW_PROD].[dbo].[DOTS_All] AMS
ON PD.Month_Name = AMS.Month
AND PD.Year = AMS.Year
AND [Medication Name] = 'CEFUROXIME'
GROUP BY
PD.[Patient Days],
PD.[Month_Name],
PD.[Fiscal_Month],
PD.[Accounting_Year],
PD.[Year]
ORDER BY
PD.ACCOUNTING_YEAR,
PD.FISCAL_MONTH
JOIN conditions do not need to refer to columns in other tables, they can as well contain constants.
The medication name was originally restricted in the WHERE clause - that eliminated all non-cefuroxime records from the resultset.
The link above will provide an excel sheet with some sample data from both the parent and child table with expected result from the query.
Alright this should be simple but I just can't wrap my head around this for some reason. Pretty much, I have a parent table that is linked to a child table. I want to pull up few of the fields from the child table and merge it with the parent fields. I want to create a view of sort in Access.
The parent record can have multiple child records (1 - many relationship). I want to only pull up one record from the child and merge with the parent. The parent table is called Tank and the child table is Tank_Inspections. The IF statement you see below is a conditional statement that helps in determining which Out of Compliance date I should be pulling up. The issue I'm having is that the Out of Compliance date is tied to inspection type. A Tank can have multiple different inspection types. They query below merges the inspection out of compliance date with few of the tank (parent) fields. However, I want to be able to add more of the child fields (in addition to the inspection out of compliance date) but I can't do that without adding those fields to the group by clause as well. If I do that, then I won't get the right amount of records.
As you can see, the left join is getting all of the records from the parent table which is what I need. If I add any more child table fields to the query, I'll also need to add them to the group by clause and then I'll get more records than what's in the parent table. Essentially, I need to only get the records from the parent table, and then merge child fields in. I may be missing few sub queries... Any suggestions? This is what I have so far and I'm getting the right amount of records. But adding more child fields to the select statement will add more rows than i need...
SELECT parent.tankid, IIf(Min(Nz(child.[tank inspection out of compliance date], #1/1/1901#)) <> #1/1/1901#, Min(child.[tank inspection out of compliance date]), IIf(Min(Nz(child.[tank inspection out of compliance date],#1/1/1901#)) = #1/1/1901# And Max(child.[tank inspection out of compliance date])>Date(), NULL, Min(child.[tank inspection out of compliance date]))) AS [Tank Inspection Out of Compliance Date]
FROM
tank as parent
LEFT JOIN
(
SELECT * FROM tank_inspections WHERE tank_inspections.[actual inspection date] is null
) AS child ON parent.tankid = child.tankid GROUP BY parent.tankid
I was able to modify Parfait suggested query below to come up with this:
SELECT
Site.[Manager] AS PM, Site.[DLA Site Code], Tank.[Name] AS [Name], Tank.[Local Name],
Tank.RPID, Tank.[Fac Num], Tank.[Status], Tank.[Type], Tank.[Capacity], Tank.[Current Prod], IIf(main.[Inspection Out of Compliance Date]<Date() AND NOT IsNull(main.[Inspection Out of Compliance Date]), 'Out of Compliance',
IIf(isnull(main.[Inspection Out of Compliance Date]) OR main.[Inspection Out of Compliance Date]=#1/1/1901#,'Unknown Compliance Status')) AS [Compliance Status], Tank.[EA], Site.Serv, Site.[Name], Tank.Comments, main.[Type], main.[Inspection Out of Compliance Date], main.[Planned Prog Date], main.[Prog Date], main.[Prog Year], main.[Planned Inspection Date], IIf(main.[Inspection Out of Compliance Date]<DateAdd('m',12,Date()) And main.[Prog Date] Is Null,'Action Required') AS [Inspection Planning Action Required], main.[Inspection Comments], tank.TankID, main.inspectionid
FROM
Site INNER JOIN
(
(
(
SELECT ti.tankid, ti.inspectionid, ti.[Type], ti.[Inspection Out of Compliance Date], ti.[Planned Prog Date], ti.[Prog Date], ti.[Prog Year], ti.[Planned Inspection Date], ti.[Inspection Comments] FROM Tank_Inspections AS ti) AS main INNER JOIN Tank ON main.TankID = Tank.TankID) INNER JOIN
(
SELECT [TankID], dlookup("InspectionID", "Tank_Inspections", "[Tank Inspection Out of Compliance Date] " & IIf(Min(Nz([inspection out of compliance date], #1/1/1901#)) <> #1/1/1901#, "= #" & Min([inspection out of compliance date]) & "#", IIf(Min(Nz([inspection out of compliance date],#1/1/1901#)) = #1/1/1901# And Max([inspection out of compliance date])>Date(), "IS NULL", IIF(Min(Nz([inspection out of compliance date],#1/1/1901#)) = #1/1/1901# And Max([inspection out of compliance date])<Date(), "= #" & Min([inspection out of compliance date]) & "#", "IS NULL"))) & " AND TankID = " & TankID & " AND [Actual Inspection Date] is null") AS MinInspectionID FROM Tank_Inspections WHERE [Actual Inspection Date] is null GROUP BY [TankID]
)AS DT ON
(
main.InspectionID = Cint(DT.MinInspectionID)
) AND (main.TankID = DT.TankID)
) ON Site.SiteID = Tank.SiteID
WHERE IIf(main.[Inspection Out of Compliance Date]<Date() And NOT IsNull(main.[Inspection Out of Compliance Date]),'Out of Compliance',IIf(isnull(main.[Inspection Out of Compliance Date]) OR main.[Inspection Out of Compliance Date]=#1/1/1901#,'Unknown Compliance Status'));
I'm close with this query, however, I'm missing a few records. The parent records don't have some of the child records. For example, some of the tank records don't have any inspection records so it's not being pulled. I need to do a left join but can't seem to figure it out with this query. Everything I try doesn't seem to work. Suggestion?
Consider the following query that uses a derived table and joins the unit level parent (Tank) to aggregated child (TankInspections). You can save the derived table as a separate stored query and just replace entire select statement and alias (DT) with query name. I include more aggregates than needed for you to check calculated columns:
SELECT Tanks.*, main.*, DT.MaxInspectionID, DT.MaxInspectionOrComplianceDate
FROM
(TankInspections main
INNER JOIN Tanks ON Tanks.TankID = main.TankID)
INNER JOIN
(
SELECT [TankID],
Max(InspectionID) As MaxInspectionID,
Min([Planned Inspection Date]) As MinInspection,
Max([Planned Inspection Date]) As MaxInspection,
Min([Inspection Out of Compliance Date]) As MinCompliance,
Max([Inspection Out of Compliance Date]) As MaxCompliance,
Max(IIF(([Planned Inspection Date]) Is Null,
IIF(ISNULL([Inspection Out of Compliance Date]),
NULL,
[Inspection Out of Compliance Date]),
[Planned Inspection Date])) As MaxInspectionOrComplianceDate
FROM TankInspections
GROUP BY [TankID]
) As DT
ON main.TankID = DT.TankID
AND main.InspectionID = DT.MaxInspectionID;
I want to create a crosstab query where the pivot is a field with natural numbers (delayed days of a document) but I want to group them (those documents delayed less than 1 week, then those delayed less than two weeks, and then the rest of documents) but I try and I only have those whose delayed days are just 1 week and no less and so on. This is my code:
TRANSFORM Count(BlueCielo.[Document Number]) AS [CuentaDeDocument Number1]
SELECT Documentos.[Disciplina Interna], BlueCielo.[Client Response Return Status], Count(BlueCielo.[Document Number]) AS [CuentaDeDocument Number]
FROM BlueCielo INNER JOIN Documentos ON BlueCielo.[Document Number] = Documentos.[Numero Documento Cliente]
WHERE (((Documentos.[Documento Interno])="N"))
GROUP BY Documentos.[Disciplina Interna], BlueCielo.[Client Response Return Status]
ORDER BY Documentos.[Disciplina Interna], BlueCielo.[Client Response Return Status]
PIVOT BlueCielo.[Delayed Days] in (0,7,14,21);
the part that I do not know how to implement is just the last paragraph:
PIVOT BlueCielo.[Delayed Days] in (0,7,14,21);
(BlueCielo is my table and [Delayed Days] is the field with the data).
When I try with
PIVOT BlueCielo.[Delayed Days] in (0,>7,>14,<14);
it gives me an error.
Can anyone help me? Thanks a lot!!
I have try with this and I have solve the problem!
PIVOT IIf([Delayed Days]<1,"0 dias",IIf([Delayed Days]<7,"<1 wek",IIf([Delayed Days]<14,"<2 weeks",IIf([Delayed Days]<21,"<3 weeks",">3 weeks"))));
I am facing some problem to calculate values from comparing dimension's value. I have 3 dimensions (Datatype, Customer, Product) and one measure (GrossSales).
What would be the MDX query if I want GrossSales for ProductID = 1,2,3 and Dataype = 4,5,6?
Here Datatype has relationship with GrossSales, Customer has relationship with GrossSales and Product has relationship with Customer.
I am trying this but doesn't work
CREATE MEMBER CURRENTCUBE.[Measures].Forecast_Gross_Sales AS
(
SELECT NON Empty [Measures].[Gross Sale]
FROM [Measures]
WHERE (
[Data Type].[ID].[ID] = 4
AND [Chain].[Customer ID] = [Measures].[Customer ID]
)
), VISIBLE = 1
, DISPLAY_FOLDER = 'Forecast'
, ASSOCIATED_MEASURE_GROUP = 'Data Types';
It looks like you are just getting started with MDX. There are some fundamental concepts that will help you get what you need. This comparison of SQL and MDX might be helpful. MDX uses the where clause as a slicer (to select certain dimension members) rather than a filter. You can't put member = somevalue in the where clause. And you can't really use the where clause to define a relationship to some other table.
Instead, your where clause would be something more like
[Data Type].[ID].[ID].&[4]
Since I can't see your data model, I can't be sure, but I would guess that [Chain].[Customer ID] = [Measures].[Customer ID] is something that you want to define the the dimension usage of your cube rather than in the query.
Edit: Now that the question has been edited, it looks like you are creating a calculated member. in this case there is no select or where clause. It will look more like this:
CREATE MEMBER CURRENTCUBE.[Measures].Forecast_Gross_Sales AS
Aggregate([Data Type].[ID].[ID].&[4], [Measures].[Gross Sale])
, VISIBLE = 1
, DISPLAY_FOLDER = 'Forecast'
, ASSOCIATED_MEASURE_GROUP = 'Data Types';
The relationship from the measure group through the Customer dimension to the Chain dimension is something that should be defined in the dimension usage. This is called a Reference dimension relationship.