Forum Discussion
Aggregation Table Not Working with Year Filter in Power BI
- Anonymous2 years ago
I've come to a workaround, mainly because, as far as I could understand the engine does not work how I imagined it.
Your aggregation table must encompass the full dataset of the facts table. Even though the engine is very good, he's not able of switching between AGG and Facts table, if the AGG does not have all of the required timeframe.
The solution was to create a data model based on a hot and cold direct query:
The HOT DQ will encompass data from the last 2 years, while the COLD DQ will encompass data prior to the last 2 years.
I've had to make a few adjustments on the measures I've created, for example:Measure = DIVIDE( CALCULATE( COUNT(HOT_cci_gpmt_ecommerce_global[article]), HOT_cci_gpmt_ecommerce_global[has_discount] = 1 ), CALCULATE(COUNT(HOT_cci_gpmt_ecommerce_global[article])) ) + IF( MIN(Dim_Calendar[date]) < [_min_updated_date], DIVIDE( CALCULATE( COUNT(COLD_cci_gpmt_ecommerce_global[article]), COLD_cci_gpmt_ecommerce_global[has_discount] = 1 ), CALCULATE(COUNT(COLD_cci_gpmt_ecommerce_global[article])) ) )The measure containing the _threshold_date, required to evaluate if the consulting of the COLD DQ is required:
_threshold_date = CALCULATE( MIN(HOT_cci_gpmt_ecommerce_global[report_date]), ALL(Dim_Calendar) )
This way:
* if the user selects the last 2 years, the AGG is hit;
* if the user selects a timeframe prior to the last 2 years, the COLD DQ is hit;
* if the user selects a timeframe encompassing the last 4 years (for instance), both the AGG and COLD DQ are hit.
Hope i was able to explain it well, and thank you for the help!
Anonymous,
I'm not aware of a way to achieve this with delivered functionality, but I wonder if a smart measure such as the one below would work. It would require adding a second instance of the DirectQuery fact table and relationships (DQ tables have a small footprint). This second fact table would not use Manage Aggregations. The concept is to see if the AGG table contains data for the specific DAX query, and then use the appropriate table. Alternatively, you could use ISBLANK ( [Primary Measure] ) instead of ISEMPTY (see which one performs better). Let me know if this works.
Smart Measure =
IF (
ISEMPTY ( 'cci gpmt AGG' ),
[Secondary Measure],
[Primary Measure]
)
Primary Measure = SUM ( 'cci gpmt ecommerce'[Column To Sum] )
Secondary Measure = SUM ( 'cci gpmt ecommerce 2'[Column To Sum] )