we have a very specific problem on calculating movement using two dates from and to in cube and details are as follows:
Product group, sub group and asset and liability are derived using client type, product type and closing balance being in credit or debit on a particular day.
Product group, sub group and asset/liability can be selected from a dimension which has a surrogate key that is stored in the fact table against the date key and account key.
Fact table is "account's daily snapshot" which has every day's data starting from the date account was opened till today and the granularity is DateKey and AccountKey.
Consider the scenario that on 15th Jan a particular account was categorised as "Asset" based on associated product type, client type and closing balance value but on the 31st because of the movements after 15th till 31st; it went into "Liability". Now consider that the user would like to see the movements between these two dates and selects "from" and "to" dates in the cube using two date hierarchies.
The "to" date hierarchy runs on a date hierarchy where as "from" date hierarchy is dependent on floating date dimension that does not have any relationship and used with linked member function to get the starting point to perform the sum on "to" date hierarchy.
Now when issuing the two dates 15th and 31st on the cube; behind the scene data from 15th till 31st comes in scope of the selection which has key for asset and liability attribute values.
So when the user choose to show dimension attributes Product group, sub group and asset/liability the cube shows values against attribute values "Asset" and "Liability" which is correct on two rows.
Users would like to see that the asset or liability should be from the "to" date only but should also be able to pass from date to get the sum of movement.
We are wondering if we can keep the closing balance from "to" date and show Product group, sub group and asset/liability dimension attributes using this closing balance and using "from" date just to calculate the sum of movements but not to have impact on Product group, sub group and asset/liability attribute values and subtract it from closing balance to get the desired result.
Any help will be greatly appreciated.
Related
Background: I have a column in a Customer dimension with a static date(e.g '2013-01-01').
This column is the result of a calculation that gets the first transaction date ever made by that certain customer. This customer dimension is linked to a fact table containing reportdate as a date column linked to a date dimension.
Goal: I want to make a calculated measure that, based on a sum of amount measure, calculates the result based on a given period between start_date(First transaction date), end_date (first transaction date + 6 months).
All i get is "cannot be determined in the current context" warnings and cannot get my head around to fix it.
All help is welcome!
Thanks in advance,
/Blixter
SOLVED I replicated the logic from the calculated measure found in the Customer table.
=CALCULATE([SumAmount];DATESBETWEEN(DimDate[Date];FIRSTDATE(FactTable[Reportdate]);DATEADD(FIRSTDATE(FactTable[Reportdate]);5;MONTH)))
I have created two list boxes with dates in an Access form to allow the user to select a date range. The user can pick a date in the first list and a later date in the second list.
The form is called Supplier History, the first list (the "from" date list) is called List3 and the second list (the "to" date list) is called List5. [Edit: List0 in code below contains suppliernames]
The dates in these lists are obtained by merging two tables. The tables involve supplier data, one table called Item Master focuses on general information on the supplier, the second table called ZMCE has transaction data.
The goal is to calculate the average price that the supplier charges, over the selected date range. The price column InfoRecPrice is in table Item Master.
For example let's say the lists have the following dates
These come from table Item Master: this table has dates (in column DateStamp) 8/24/2015, 9/1/2015, 10/1/2015, 11/1/2015, 12/9/2015, 1/4/2016, 2/1/2016, 3/1/2016, 4/1/2016, 5/1/2016, 6/1/2016. Table ZMCE has all the other dates, in column PODate.
Let's say the user picks the highlighted dates. I want the code to calculate the average price (price is in item master) over that time period even though the exact highlighted dates are not in that specific table.
The code below gives me a blank output, no matter what dates I select (even if I select those that are exactly the dates in the item master table):
SELECT Avg([Item Master].InfoRecPrice) AS Expr1
FROM [Item Master]
WHERE ((([Item Master].DateStamp)>=[Forms]![Supplier History]![List3] And ([Item Master].DateStamp)<=[Forms]![Supplier History]![List5]) AND (([Item Master].SupplierName)=[Forms]![Supplier History]![List0]));
Data: I have a single row that represents an annual subscription to a product, it has an overall startDate and endDate, there is also third date which is startdate + 1 month called endDateNew. I also have a non-related date table (called table X).
Output I'm looking for: I need a new column called Categorisation that will return 'New' if the date selected in table X is between startDate and endDateNew and 'Existing' if the date is between startDate and endDate.
Problem: The column seems to evaluate immediately without taking in to account the date context from the non-related date table - I kinda expected this to happen in visual studio (where it assumes the context is all records?) but when previewing in Excel it carries through this same value through.
The bit that is working:I have an aggregate (an active subscriber count) that correctly counts the subscription as active over the months selected in Table X.
The SQL equivalent on an individual date:
case
when '2015-10-01' between startDate and endDateNew then 'New'
when '2015-10-01' < endDate then 'Existing'
end as Category
where the value would be calculated for each date in table X
Thanks!
Ross
Calculated columns are only evaluated at model refresh/process time. This is by design. There is no way to make a calculated column change based on run-time changes in filter context from a pivot table.
Ross,
Calculated columns work differently than Excel. Optimally the value is known when the record is first added to the model.
Your example is kinda similar to a slowly changing dimension .
There are several possible solutions. Here are two and a half:
Full process on the last 32 days of data every time you process the subscriptions table (which may be unacceptably inefficient).
OR
Create a new table 'Subscription scd' with the primary key from the subscriptions table and your single calculated column of 'Subscription Age in Days'. Like an outrigger. This table could be reprocessed more efficiently than reprocessing the subscriptions table, so process the subscriptions table as incrementals only and do a full process on this table for the data within the last 32 days instead.
OR
Decide which measures are interesting within the 'new/existing' context and write explicit measures for them using a dynamic filter on the date column in the measures
eg. Define
'Sum of Sales - New Subscriptions',
'Sum of Sales - Existing Subscriptions',
'Distinct Count of New Subscriptions - Last 28 Days', etc
I am trying to apply some Time Intelligence functions in my PowerPivot workbook concerning projects and money received for them. I have three relevant tables; Matters, Payments, and a Date Table.
Each matter has a creationDate, and a closureDate(from a linked table). Likewise, each payment has a date. I have reporting set up decently, but am now trying to use Time intelligence to filter this a bit more clearly.
How can I set a PowerPivot Pivot Table up so that the only Matters which show are those which existed within the period selected. e.g. If I select a slicer for 2014, I don't want to show a matter created in 2015, or one which was closed in 2013. The matter should have been active during the period specified.
Is this possible?
You want to show all the matters EXCEPT those where the CreationDate is after the upper limit of the date range you are looking at or the ClosureDate is before the lower limit of the date range you are looking at.
Assuming you have a data structure like this, where the left-hand table is the Matters and the right-hand one is the Payments:
If you have a calculated field called [Total Payments] that just adds up all the payments in the Payments table, a formula similar to this would work:-
[Payment in Range]:=IF(OR(MIN(Matters[Creation Date])>MAX('Reporting Dates'[Date]),MAX(Matters[Closure Date])<MIN('Reporting Dates'[Date])),BLANK(),[Total Payments])
Here is the result with one month selected in the timeline:
Or with one year selected in the year slicer:
NOTE: in my example, I have used a disconnected date table.
Also, you will see that the Grand Total adds up all the payments because it takes the lowest of all the creation dates and the highest of all the closure dates to determine whether to show a total payment value. If it is important that the Grand Total shows correctly, then an additional measure is required:
[Fixed Totals Payment in Range]:=IF(COUNTROWS(VALUES(Matters[Matter]))=1,[Payment in Range],SUMX(VALUES(Matters[Matter]),[Payment in Range]))
Replace the [Payment in Range] in your pivot table with this new measure and the totals will show correctly, however, this will only work if Matters[Matter] is used as one of the fields in the pivot table.
Use filters & the calculate function.
So, if you're Summing payments, it would look like.....
Payments 2014:= CALCULATE( SUM([Payments]), DateTable[Year]=2014)
The Sum function takes the entirety of payments & the filter function will only capture payments w/in 2014, based on the data connected to your date table.
I've created a new measure which uses [TotalSales] and 'SAMEPERIODLASTYEAR' to calculate the previous year's sales, see below:
=CALCULATE([TotalSales], SAMEPERIODLASTYEAR(Dates[Date]))
This all works fine if I create a pivot that displays individual dates (e.g. 01/01/2015) and then the new measure 'previous year sales' value next to it. My problem occurs when I want to change the pivot and display previous year sales by year, quarter or month - with any of these options I get no sales value.
I'm using a 'Dates' table which is linked to the Sales table.
Am I right in thinking I can re-aggregate sales in this way? I have seen an error message which says something about not been able to aggregate a non-contiguous value or date.
I've had a good look to see if anyone else has experienced the same problem, but can't see anything. Any guidance would be helpful.
Regards,
Martyn
Yes you can re-aggregate in this way. Your formula is correct would handles the changes to the aggregation level.
I would check that your 'Dates' table is marked as a date table. Ensure that the year, quarter & months are in this date table and not in your Sales table. Make sure that your date table has one record for each day between the beginning of your sales data set and the end. Check behavior in Power View if you are using Excel 2013.