how to calculate count distinct based on a measure in OLAP cube - ssas

I'm trying to write an MDX query for a calculated member "Daily Active users" in my SSAS OLAP cube based on an attribute in the fact table called "IsDailyActive'
I have a measure called "Active Users" that uses the COUNT DISTINCT aggregation from the "Fact Activity" table on the UserId column. I want to reuse that measure and calculate distinct count of users by sepcifying the filter 'Is Daily Active' as True in my query.
I tried this, but it gives me null
WITH
SET MySet AS
{[Measures].[Active Users]}
MEMBER [Measures].[Daily Active Users] AS
DISTINCTCOUNT(MySet)
SELECT
{[Measures].[Daily Active Users]} ON COLUMNS
FROM MyDataCube
WITH
SET MySet AS
{[Measures].[Active Users]}
MEMBER [Measures].[Daily Active Users] AS
DISTINCTCOUNT(MySet)
SELECT
{[Measures].[Daily Active Users]} ON COLUMNS
FROM MyDataCube
WHERE
([Is Daily Active].[Boolean].&[True])
What I'm doing wrong?
Note: IsDailyActive column in the "FactActivity" table is of type "bit" so it has 0 or 1 values in the rows.

If the measure Active Users already exists in the cube script then why does the following not work?
SELECT
{[Measures].[Active Users]} ON COLUMNS
FROM MyDataCube
WHERE
([Is Daily Active].[Boolean].&[True])

Related

I want a query to get LIST of averages of users in postgres

I want to get the list of averages from a table who has the list of users
Not single average but a list
select avg(no_of_interactions) from table name;
where I want to get the list of avg interactions of {user1,user2,user3} so on
it is giving me only one average
It should be
select <column>, avg(no_of_interactions)
from table <name>
group by <column>;
where <column> is userName or userId or anything else you want to use as grouping condition

Create dynamic Metric, which will be based on various dimensions/ filters applied

I have a table "Trans" which contains the acccountNumbers and other dimensions like Facility , Status etc.
I need to create a calculated member in SSAS where the logic would be
Count of Accounts in a group / Total accounts.
Count of Accounts in a group would be based on the Dimension filter I provide.
For e.g. If I provide the facility then I need the Count of accounts (In numerator) group be different facilities.
Likewise If I provide the Status I would need the numerator to be grouped as per the data in Status table.
Table Name
Trans (AccountNumber, facility,Status) -- This is fact table
Dimension tables
Facility( Id, Facility_name)
Status (Id, Status)
Not sure how to go about it.
EXISTING is a useful function, so maybe something like:
COUNT(
EXISTING [AccountNumber].[AccountNumber].MEMBERS
)

MS access calculated field sub table

I would like to add a calculated field to many of my tables and will be able to use this new technique many times.
I have sub records such as values for SalePrice and I would like to have these totals show in an employees record.
I would appreciate a sample query and how to implement considering the following data:
Table 1 (Employees): ID, EmployeeName, [Calculated Field]
Table 2 (Sales): ID, InventoryItem, SalePrice, QuantityOrdered
I would like to fetch [SalePrice] x [QuantityOrdered] in 2 scenarios:
Total Sales to date
Total Sales within a date range (where these 2 values can be entered
on a form) for administration purposes as our employees are paid
commission only.
I'm used to adding table fields in both Layout and Design view.
Kind regards, Mikey.
This should get you started: MS Access SQL: http://office.microsoft.com/en-nz/access-help/access-sql-basic-concepts-vocabulary-and-syntax-HA010256402.aspx. Calculated fields in queries: http://office.microsoft.com/en-nz/access-help/create-a-calculated-field-in-a-query-mdb-HP005188023.aspx.

Can't get sub query to work

I have 2 queries that work fine by themselves but I've been struggling to get them to work together. I have a table of audits and I am trying to count the audits by auditor. I am using a form to get the date range and the auditor. The auditors are in a table named tblUser. The main table is tblParatransitPullOutAudit. There is a field in this table named AuditId which tells me what Audit each record belongs to. There may be many records with the same Audit ID, these count as 1 audit. I want to count how many audits by date range and Auditor. Any help will be greatly appreciated.
SELECT
t.Contractor,
Count(t.PK_ParapullOut) AS Audits
FROM
tblUser
INNER JOIN
tblParatransitPullOutAudit AS t
ON tblUser.PK_User = t.Auditor
WHERE ((t.AuditDate) Between forms!frmTotalAuditsDateRangeAuditor!txbStartDate.value And forms!frmTotalAuditsDateRangeAuditor!txbEndDate.value)
And ((tblUser.PK_User)=Forms!frmTotalAuditsDateRangeAuditor!cboAuditor.value)
GROUP BY Contractor;
SELECT
p.Contractor,
Count(p.AuditID) AS Audits
FROM
(
SELECT DISTINCT
p.Auditor,
p.AuditDate,
p.contractor,
p.auditid
FROM tblParatransitPullOutAudit AS p
) AS Total
WHERE ((p.AuditDate) Between forms!frmTotalAuditsDateRange!txbStartDate.value And forms!frmTotalAuditsDateRange!txbEndDate.value)
GROUP BY p.Contractor;

MDX equivalent to SQL's GROUP BY for excluding duplicate rows

My cube has a fact table that contains a row for every modification made to any entity. What I need is a measure that will return a count of the entities based on the selected dimensions.
So if the user selects a month from the date dimension then the measure should return the number of entities that were modified that month (rather than the number of modifications).
In SQL this would be something like:
SELECT EntityID, COUNT(*)
FROM FactTable
WHERE Date BETWEEN X AND Y
GROUP BY EntityID
How can you do this in MDX? Surely this would be an extremely common scenario with cubes.
Your t-sql query is equivalent of mdx query:
select
[Measures].[<Fact rows count measure>] on columns,
<Entity dimension members> on rows
from [<Cube Name>]
where (<month member>)
In the above query [Fact rows count measure] would be a measure with aggregation formula Count - count of rows
However, if you need to return the distinct count of entity members when you slice by another dimension, you basically have several options:
create a distinct count measure on the entityID key
create a calculated measure with expression: count(exists(existing [Entity].[Entity].[Entity].MEMBERS,,'Measure Group Name'))
HTH,
Hrvoje Piasevoli