I have the data that is going to rollover everymonth if the data condition is active. Below is the example
Source data:
DID YearMonth Createddatekey count
a 201307 20130701 1
b 201307 20130701 1
a 201308 20130701 1
b 201308 20130701 1
c 201308 20130801 1
Required output:
Expected
output
Yearmonth Count
201307 2
201308 1
I can get the results in the SQL by just adding the condition as below.
select Createdatekey,count(*) from table with (nolock)
Where Createdatekey>=20130701 and YearMonth=201307
Group by Createdatekey
But when I created the Hierarchy in the Datedimension by joining the Createdatekey it's giving the combine relsult irrespective of months.
How can I achieve that SQL condition what I written in SSAS cube model?
If I understand you correctly, you are trying to create a measure in a SSAS cube that provides a distinct count of DID from your fact table based upon the YearMonth of the CreateDateKey.
I'm not sure if you are doing multidimensional or tabular, so here are suggestions for both. It sounds like you already have your table properly related to your date dimension. For multidimensional, you can create a measure and make sure you select DID as the source column and Distinct count as the usage.
In tabular, create a calculated measure that is
distinctcount([DID])
Related
I'm creating a cube whose stock values should only conclude the last day each month's balance and value.
Hence, I've created the following Query in SSMS:
Create table #theStockTable(
Stock int,
StockValue INT,
DateKey int
)
INSERT INTO #theStockTable
VALUES(3,5, 20170211),
(3,5,20170228),
(1,4,20170331),
(1,4,20170330)
SELECT CAST(CONVERT(varchar, DateKey, 112) AS numeric(8, 0)) AS DateKey, SUM(Stock) AS [CL Stock], SUM(StockValue) AS [CL Stock Value]
FROM #theStockTable
WHERE CONVERT(date, CONVERT(varchar(10), DateKey)) = eomonth(CONVERT(date, CONVERT(varchar(10), DateKey)))
GROUP BY DateKey
In SSMS this returns the correct values:
DateKey CL Stock CL Stock Value
20170228 3 5
20170331 1 4
However, when I create an OLAP cube using SSAS, and use the Query above as the Named Query for my fact table #theStockTable and the same Query as my only partition of the same fact table and deploy and execute the cube, I have a situation where I get different values on each day of every month, but I only want to have the values for each month's last day.
I have used New Project.. -> Import from Server (multidimensional model or data mining model) in SSAS. It is important that the users must be able to browse the cube as they presently do.
The cube whose meta data I have copied contains every day's values on the stock table. May there be some metadata change I need to make in addition to the Query modification I have done in Edit named Query.. in Data Source View and replacing the old Query in the partition with my new Query?
Hopefully someone can shed some light into this.
EDIT
To clarify my request, some users of the cube has explained that it is rather slow to browse in for instance Excel, mainly because my Stock measure is much bigger than it is required to be. As it is now, it returns every StockValue and Stock of each product and each day. I want to only include the total balance of StockValue and Stock of the last day of the month. All other stock values are redundant.
For instance, browsing my DimDate dimension table with the measurements Stock and StockValue should have this return set:
DateKey Stock StockValue
20170131 0 0
rather than the whole return set which is returned now:
DateKey Stock StockValue
20170101 3 5
20170102 4 6
20170103 1 1
20170131 0 0
I think you already had a date dimension in your cube, if yes, then follow these steps:
Add an additional attribute [IsLastDay] with value 0/1 in the date dimension to indicate if the current date record is the last day of that month or not.
2.Add a calculate measure [CalStock] with this formular:
([Measures].[StockValue],[Date].[IsLastDay].&[1])
3.Fire this query to return the expected result:
select {[CalStock]} on 0,
non empty{[Date].[Date].[Date]} on 1
from [YourCube]
This is how my data model looks like:
Id Status StartDate
1 StatusA 01/01/2015
1 StatusB 01/03/2015
1 StatusC 01/05/2015
2 StatusA 01/04/2015
2 StatusB 01/08/2015
I am trying to get the max date of StatusB column per Id.
This is how my dimension looks like:
=If(Match(Status,'StatusB'),Timestamp(StartDate))
It works fine but it also gives me an additional duplicate row with Empty max date.
My Straight Chart table contains only these 2 columns. If i remove the Max Date dimension, it shows one record per Id
What am i missing here?
No need to add the filter in the dimension. QV allow calculated dimension but they can cause a lot of performance issues. (basically when calculated dimensions are used QV is createing new "virtual" table in the memory with the new dimension. With big datasets this can drain your ram/cpu)
For this cases its much better to "control" the dimension through the expressions. In your case just add Status as dimension and type the following expression:
max( {< Status = {'StatusB'} >} StartDate)
And in Numbers tab change the format setting to Timestamp.
Stefan
you can look like this;
aggr(max(StartDate), Status, StartDate)
Hi I have a table like this:
idCustomer | idTime | idStatus
---------------------------------
1 | 20010101 | 2
1 | 20010102 | 2
1 | 20010103 | 3
2 | 20010101 | 1
...
I have now added this table as a factless fact table in my cube with a measure which aggregates the row count for each customer, so that for each day I can see how many customers are at each status and I can drill down to see which customers they are.
This is all well and good but when I roll it up to the month or year level it start summing up the values of each day where instead I want to see the last non empty value.
I'm not sure if this is possible but I can't think of another way of getting this information without creating a fact table with the counts for each status on each day and loosing the ability to drill down.
Can anyone help??
An easy way to get what you want would be to convert your factless fact table to one having a fact: the count. Just add a named calculation to the table object in the data source view. Name the calculation like you want your measure to be named, and use 1 as the expression. Then you can define a measure based on this calculation using the aggregate function "LastNonEmpty", and use this instead of your current count measure.
I have a table with columns that store dates of various events, like so:
<pre>
PersonID DatePassedExam1 DatePassedExam2
1 NULL NULL
2 01-11-2012 NULL
3 01-12-2012 10-12-2012
</pre>
I want to build a cube to see counts of people who have passed exam1 and exam2 by person attributes and time, e.g. year to date.
So,
YTD for Oct2012: exam1count=0, exam2count=0
YTD for Nov2012: exam1count=1, exam2count=0
YTD for Dec2012: exam1count=2, exam2count=1
I'm guessing this needs semi-additive aggregation?
I can't make changes in the database (without difficulty) and am not using Enterprise edition.
Any advice gratefully received.
Thanks,
Dal
I would unpivot your table to pass the columns: PersonID , Exam , DatePassed. Your sample data would result in 1 row for PersonID 2 and 2 rows for PersonID 3.
I would then create an Exam dimension and link it.
Then I would create the measure as a Distinct Count of PersonID.
I am building first cube in SSAS 2012 Tabular modeling. I got one fact table contains following columns
TermDate StudentKey PaperKey marks CumulativeNoOfStudents
20100601 1 1 70 2
20100601 2 1 70 2
20100601 3 1 69 3
20100601 4 2 68 1
Now i need to generate Cumulative Number Of Students (5th column) as an output (calculated column) against each row using DAX.
Can someone help me to build the DAX formula please.
On the basis that your StudentKey is numeric, sequential and unique you can use the following:
=CALCULATE(COUNTROWS(Table), FILTER(Table,Table[StudentKey]<=EARLIER(Table[StudentKey]))
Assuming your table is called 'Table'
HTH
Jacob
on the basis of some assumption like studentkey is numeric and your date table is DimDate with date as unique column, and fact table name as FactStudent can use the below formula also.
Cumalative No of Students :=CALCULATE (CountRows(FactStudent), FILTER(ALL(DimDate[Date]), DimDate[Date] <= MAX(DimDate[Date])))