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])))
Related
I am pretty new to SQL, but i need to use it for my new job as the project requires it and as I am a non-IT-guy, it is more difficult for me, because thats my first time I work professionally with SQL.
Hopefully you can help me with it: (Sry for my english, i am a non-native speaker)
I need to start a query where I get unequal IDs from 2 different reference dates.
So I have one Table with following data:
DATES ID AMOUNT SID
201910 122424 99999 1
201911 41241242 99999 2
201912 12412424 -22222 3
...
GOAL:
So the ID's from the DATE: 201911 shall be compared with those from 201910
and the query should show me the unequal ID's. So only the unmatched ID's shall be displayed.
Out of this query, the Amount should be summed up and grouped into SIDs.
If you have two dates and you want sids that are only on one of them, then:
select sid
from t
where date in (201911, 201910)
group by sid
having count(distinct date) = 1;
Problem:I am trying to make a Inventory Management Database on Microsoft Access 2010, and since i needed records date wise my Table looks like follows
SKU 2016-03-16 2016-03-17 2016-03-18 ... Total
AAA 10 -5 15 ... 20
BBB 05 05 25 ... 35
CCC 06 -5 24 ... 25
This way i wanted to add records for each day, but i am unable to make a "Total" column which will total all the columns (Sum(Columns*))
I am aware of sum and groupby but that works across multiple rows i am looking for something which can do the same for column
Expected Solution: A way either by Sql Query or VBA to total all the columns for SKU AAA,BBB,CCC, if not possible to total in the same table then i am open to total the columns in a new table.
Such a table is normally result of pivoting summary data. Real data would look like:
SKU, Date, Quantity
...
Then probably you would want to create a PIVOT table using SKU for rows, Date for Columns and Quantity for data (default operation is SUM). It would have the row totals by default.
It may have been named crosstab, cross tab .. or so in Access 2010.
(you may want to do the pivoting in Excel)
The data I am working with is oil and gas production data. The production table uniquely identifies each well and contains a time series of production values. I want to be able to calculate a column that contains the month number occurrence of production for every well in the production table. This needs to be a calculation, so I can graph the production for various wells based on the production month, not the calendar month. (I want to compare well performance across wells over the life of wells.) Also note that there could be gaps in the production data so you can't depend on having twelve months of sequential production for each well.
I tried using the answer in this postRankValues but the calculation would never finish. I have over 4 million rows of production data.
In the table shown below, the values shown in ProdMonth is what I need to calculate based on their time occurrence shown in ProdDate. This needs to be performed as a row calculation for each unique WellId
Thanks.
WellID ProdDate ProdMonth
1 12/1/2011 1
1 1/1/2012 2
1 2/1/2012 3
1 3/1/2012 4
… … …
1 11/1/2012 12
2 3/1/2014 1
2 4/1/2014 2
2 5/1/2014 3
2 6/1/2014 4
2 7/1/2014 5
… … …
2 2/1/2014 12
I would create a new date table that has a row for each day (the granularity of your data). I would then add to that table the ProdMonth column. This will ensure you have dates for all days (even if there are gaps in the well reporting data). Then you can use a relationship between the well production data and the Date table on the ProdDate field. Then if you pull in the ProdMonth from the date table, you'll have a list of all of the ProdMonths (hint: you may need to select 'show values with no data' on the field right click menu in the fields well). Then if you add to the same visualization WellID you should be able to see which wells were active in which ProdMonth. If WellID is a number, you might need do use the 'do not summarize' feature on the WellID to get the result you desire.
I posted this question on the PowerPivotPro and Tom Allan provided the DAX formula I needed. First step was to calculate a field that concatenated Year and Month (YearMonth). Then utilized the RANKXX function as such:
= RANKX ( FILTER ( Data, [WellID] = EARLIER ( [WellID] ) ), [YearMonth], , 1, DENSE )
That did the trick and performed fairly quickly on 12mm rows.
In Powerpivot, I have a problem in ranking in Table 1, based on Sales and Year. I want to have the result like that:
Year Store Sales **Rank**
2013 A 200 3
2013 B 250 2
2013 C 300 1
2014 A 350 2
2014 B 300 3
2014 C 400 1
Which rank function could I use to have this rank result?
Thanks in advance.
Tran,
Probably the smartest way to go is to use the 'X' functions. They can be a bit tricky and non intuitive, yet are extremely powerful.
First, create a simple measure to calculate the total sales:
TotalSales:=SUM(Stores[Sales])
Then, use this formula below to calculate the rank (per store per year):
Rank:=RANKX(ALL(Stores[Store]), [TotalSales])
That should do what you are looking for. Once those two measures are ready, create a new powerpivot table, dray Year and Store onto rows pane and add required values.
ALL function overwrites the applied rows filter and thus allows to calculate rank per year.
The result should look like this:
Hope this helps.
I'm attempting to find the amount of subjects that only have a baseline weight and not a weight at 6 Months or 12 months. The database provided has roughly 8000 entries and we need to create a query to find this information - they mention it can be achieved through joining - but I continually get results that are tied in with 6 months weight and 12 months weight when I only need that data from baseline weight. For instance, I easily found the data for the amount of people that have baseline weight and 6 months weight
SELECT DEMO.ID, DEMO.BL_WGT, [SIX MOS].WEIGHT_6MOS
FROM DEMO RIGHT JOIN [SIX MOS] ON DEMO.ID = [SIX MOS].ID;
I can't for the life of my understand how to qualify this data to find only those entries with baseline weight. Any help would be appreciated thank you! Here is the exact question from the assignment.
Part V. Create a new table named WT_LOSS_ALL that has the following fields:
ID Number
Baseline Weight
6-Month Weight
12-Month Weight
Use the proper join(s) in order to answer the follow questions:
How many participants have only Baseline weight? Baseline & 6 Month Weight? All 3 measures? (5 points)
Try this:
Assumption is the default value for the field is null and baseline always have a value
Baseline weight only
Select count(id) from WT_LOSS_ALL where 6mos is null and 12mos is null
Baseline weight and 6mos
Select count(id) from WT_LOSS_ALL where 6mos is not null and 12mos is null
All 3
Baseline weight and 6mos
Select count(id) from WT_LOSS_ALL where 6mos is not null and 12mos is not null