Forum Discussion
Slow Calculate with distinct count
- 4 years ago
Thanks - it looks like my earlier assumption "DimDato is marked as a date table, or the DimDato[Dato] column is on the one-side of a relationship." doesn't hold. As a result, the filters on DimDato are not being removed automatically when a filter is applied to the column DimDato[Dato].
For my measure to work, DimDato should be marked as a Date table with DimDato[Dato] being selected as the date column (usual setup for time intelligence functions).
Alternatively, you could just rewrite the measure as:
Measure = CALCULATE( [Antal betalte donorer], DATESINPERIOD ( DimDato[Dato], MAX ( DimDato[Dato] ), -1, YEAR ), REMOVEFILTERS ( DimDato ) )
Interesting...the measure I posted should produce identical results to the measure you posted. (comparison of measures with same structure https://dax.do/drM0jkPkJD6b4T/)
π€·β
In any case, my main point was about avoiding using table functions to produce scalar values, and avoiding filtering a table when you can filter a column.
By "12 months back" you mean "over the 12 month period ending on the maximum date visible in the current filter context" don't you?
This is what my chart looks like using Your measure:
π€
And the measure for Antal betalte donorer:
- OwenAuger4 years ago
Super User
Thanks - it looks like my earlier assumption "DimDato is marked as a date table, or the DimDato[Dato] column is on the one-side of a relationship." doesn't hold. As a result, the filters on DimDato are not being removed automatically when a filter is applied to the column DimDato[Dato].
For my measure to work, DimDato should be marked as a Date table with DimDato[Dato] being selected as the date column (usual setup for time intelligence functions).
Alternatively, you could just rewrite the measure as:
Measure = CALCULATE( [Antal betalte donorer], DATESINPERIOD ( DimDato[Dato], MAX ( DimDato[Dato] ), -1, YEAR ), REMOVEFILTERS ( DimDato ) )- Bokazoit4 years ago
Continued Contributor
You are ΓΌber smart and skillful! π
What happens?
Is it because of my USERELATIONSHIP or?
It is **bleep** quick now π- OwenAuger4 years ago
Super User
πGlad to hear it π
I believe the main issue was FILTER ( ALL ( DimDato...) )
Firstly, it's more efficient to apply a filter to a single column (in this case DimDato[Dato]) than the entire unfiltered table ALL ( DimDato ).
Also, iterating row-by-row with FILTER always runs the risk of performing poorly. In this example we have an alternative, which is to use DATESINPERIOD to generate the required filter more efficiently by specifying a one-year period ending on the maximum date.
A secondary issue was using table functions LASTDATE and SAMEPERIODLASTYEAR to produce scalar values. I would generally only use these functions if I need to apply the result as a filter, and it turns out we can avoid these in this case anyway.
USERELATIONSHIP itself wasn't an issue as far as I can see - it simply activated the required relationship but wasn't the main performance issue.
Regards,
Owen