Forum Discussion
Rewrite Filter function with better option (Optimize Dax Measure)
- Anonymous6 years ago
I can solve it using lastnonblank function, everything works fine now
These are the queries that I measured:
With your measure:
DEFINE
---- MODEL MEASURES BEGIN ----
MEASURE Work[Load] =
var maxMonthId = MAX( Work[month_id] )
var result =
CALCULATE(
SUM( Work[pct_assigment_monthly] ),
KEEPFILTERS( 'Calendar'[month_id] = maxMonthId ),
KEEPFILTERS(
TREATAS(
{1002, -1, 1001},
Project[project_category]
)
)
)
return
result
---- MODEL MEASURES END ----
VAR __DS0FilterTable =
TREATAS({2020}, 'Calendar'[Year])
EVALUATE
SUMMARIZECOLUMNS(
ROLLUPADDISSUBTOTAL(
ROLLUPGROUP(
'Calendar'[month_description],
'Calendar'[month_id],
'Regions'[region_desc],
'Machine Sector'[sector_desc],
'Customer'[customer_desc]
), "IsGrandTotalRowTotal"
),
__DS0FilterTable,
"Load", 'Work'[Load]
)
------------------------------------------------------------------------------------------------
With the first version of the measure (I only changed maxMonthId in order to use as a variable):
DEFINE
---- MODEL MEASURES BEGIN ----
MEASURE Work[Load] =
VAR maxMonthid =
MAX ( 'Work'[month_id] )
VAR result =
CALCULATE (
SUM ( Work[pct_assigment_monthly] ),
FILTER ( 'Calendar', maxMonthid = 'Calendar'[month_id] ),
FILTER (
Project,
Project[project_category] = 1001
|| Project[project_category] = 1002
|| Project[project_category] = -1
),
CROSSFILTER ( 'Leave Reason'[leave_reason_id], Work[leave_reason], NONE )
)
RETURN
result
---- MODEL MEASURES END ----
VAR __DS0FilterTable =
TREATAS ( { 2020 }, 'Calendar'[Year] )
EVALUATE
SUMMARIZECOLUMNS (
ROLLUPADDISSUBTOTAL (
ROLLUPGROUP (
'Calendar'[month_description],
'Calendar'[month_id],
'Regions'[region_desc],
'Machine Sector'[sector_desc],
'Customer'[customer_desc]
),
"IsGrandTotalRowTotal"
),
__DS0FilterTable,
"Load", 'Work'[Load]
)
Best
D
- Anonymous6 years agoNot applicable
4371 rows (including the total), if I put all dimensions of the model, the result will be bigger, the fact table has 730K rows.
- Anonymous6 years agoNot applicableYeah... This is a lot of rows. For a reporting tool that should summarize data, this is really unusual to return that many rows. Also, the speed depends on the hardware you use.
I suppose that for a decent amount of rows the measure will be very fast.
Best
D- Anonymous6 years agoNot applicable
But everything works fine if I remove the Date filter, this one: FILTER ( 'Date', maxMonthid = 'Date'[Month ID] )
Obviously, the result of the measure doesn't work for me. So, there is another idea to replace it?