Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago

Modeling for SCD2 type fact table

I'm dealing with a model that has a fact table more closely modeled to an SCD 2.

InstalledServiceID	ServiceLocationID	ServiceID	Service	AccountID	AddressID	GeoCode	InstalledFeatureID	Qty	Cost	Price	TotalNet	MonthlyInstallment	ARPU	Installed	ServiceStart	ServiceEnd	FeatureStart	FeatureEnd	RecordStart	RecordEnd
112438	0	257	9783234324	16072	979117	2501737000	452999	1	0.0000	0.0000	0.0000	0.0000	0.00000000	1	2005-07-19 11:33:05.000	9999-09-09 00:00:00.000	2005-07-19 00:00:00.000	9999-09-09 00:00:00.000	2005-07-19 11:33:05.000	NULL​


This table is essentially a service history table down to the SKU level tracking Monthly Recurring Revenue.  Customers can change quantities of features within a contracted service over time, so these records capture each change.

In PowerBI I created the following DAX measure:

Base MRC = 
VAR MAXDATE =
    MAX ( ___DateDimension[Date] )
VAR MINDATE =
    MIN ( ___DateDimension[Date] )
VAR CurrentFeatureService =
    DATE ( 9999, 9, 9 )
VAR Historic =
    SELECTEDVALUE ( __Filters[Show Historic?], FALSE () )
VAR EndDates =
    ADDCOLUMNS (
        ALL ( InstalledItems[InstalledFeatureID] ),
        "Last Date", CALCULATE (
            MAX ( InstalledItems[RecordStart] ),
            KEEPFILTERS(FILTER (
                InstalledItems,
                InstalledItems[RecordStart] <= MAXDATE
                    && InstalledItems[FeatureStart] <= MAXDATE
                    && (
                        InstalledItems[RecordEnd] = BLANK ()
                            || InstalledItems[RecordEnd] > MINDATE
                    )
                    && InstalledItems[FeatureEnd] >= MINDATE
            ))
        )
    )
VAR FilteredDates =
    TREATAS (
        EndDates,
        InstalledItems[InstalledFeatureID],
        InstalledItems[RecordStart]
    )
RETURN
    IF (
        Historic,
        CALCULATE (
            [Base Revenue],
            FilteredDates,
            ProductCatalog[RecurringPeriod] = "M"
        ),
        CALCULATE (
            [Base Revenue],
            FilteredDates,
            ProductCatalog[RecurringPeriod] = "M",
            KEEPFILTERS(
                FILTER(
                    InstalledItems,
                    InstalledItems[FeatureEnd] = CurrentFeatureService 
                        && InstalledItems[RecordEnd] = BLANK ()
                )
            )
        )
    )

This works fine on the summary table to show month over month what the given MRR would have been by product.
When I implement drillthrough it tanks.

I'm trying to figure out a better way to model this that won't result in a petabyte of data.  I need to be able to filter on a given date range and get any service that was active in that time period.  If there are multiple records for that service due to changes, I would need the latest record.

 

5 Replies