Forum Discussion

ciken's avatar
ciken
Icon for Resolver I rankResolver I
2 years ago

Use CalculateTable as reference for measure

Good afternoon. It was suggested to me to take a measure and remove the VAR for calculated table and create an actual Calculated Table then reference that for the remainder. It would help reduce the processing time and provide quicker access to the data. However, when I took the Calculated Table section and moved it, I am struggling with trying it to a date table and getting the results I want. 

 

Here is my original measure:

# Active Customers =
VAR ActiveDate =
    CALCULATE (
        MAX(CalendarTable[Dates]),
        ALLSELECTED ( CalendarTable[Dates] )
    )
VAR CustomersWithActiveDate =
    CALCULATETABLE (                        -- Prepares a table that
        ADDCOLUMNS (                        -- for each customer contains
            SUMMARIZE('Line Items',
            'Line Items'[customer_id],
            'Line Items'[Brand])
            ,  -- the date when they are considered active until
            "@ActiveThrough", [Active Through]
        ),
                ALLSELECTED ( 'Customer Table' ),       -- Regardless of local filters on Customer
        CalendarTable[Dates]<= ActiveDate,
            'Line Items'[Order Status] IN {"Shipped", "Authorized", "Captured", "Completed", "Partially Refunded"}
            &&'Line Items'[AS vs SO]="Autoship"-- and on Date
    )
VAR ActiveCustomers =
    FILTER (                              
        CustomersWithActiveDate,          -- Filters the customers
        [@ActiveThrough]
            >=ActiveDate  -- falls within the current time period
        )
VAR Result =
    COUNTROWS ( ActiveCustomers )         -- The count of the active customers does not
                                        -- use the Sales table (no sales in the period)
RETURN
Result


I moved the entire VAR CustomersWithActiveDate to it's own calculated table and then replaced Active Customers with 

FILTER (                              
        'Subscription',          -- Filters the customers
        [@ActiveThrough]
            >=ActiveDate  -- falls within the current time period
        )

But my results put a tick mark in every month prior to their first order and I can't seem to build a relationship between the ActiveThrough and DateTable. 

Any advice? What am I missing?

4 Replies