Forum Discussion
Distinct CountX?
- 5 years ago
Ok I actually got it figured out, and it was a LOT easier than I thought it should have been 😄
First, I got rid of the relations between the tables.
Then it was just a matter of creating the following measure:
Measure = VAR StartDato = MIN ( Dato[Dato] ) VAR SlutDato = MAX ( Dato[Dato] ) RETURN CALCULATE ( DISTINCTCOUNT('nexus2 Fact_VisiteretTid'[CPRnrKort]), FILTER ( 'nexus2 Fact_VisiteretTid', ( 'nexus2 Fact_VisiteretTid'[Start] <= SlutDato && 'nexus2 Fact_VisiteretTid'[Stop] >= StartDato ) ) )Seriously, it solved all my problems, and the result validates. Go figure XD
Whoops - no it was the second. The first killed my visual
Error was something along the lines of "Calculation error in the measure. There were many values, where there was only expected one" (sorry for the translation)
I'll hazard another guess (It's hard to pinpoint an adequate solution without sample data and the structure of the model). Let's see if taking the table calculation to a VAR makes a difference:
Measure =
VAR _Table =
CALCULATETABLE(
VALUES( 'nexus2 Fact_VisiteretTid'[CPRnrKort] ),
FILTER (
'nexus2 Fact_VisiteretTid',
'nexus2 Fact_VisiteretTid'[Start] <= MAX ( Dato[Dato] )
&& (
ISBLANK ( 'nexus2 Fact_VisiteretTid'[Stop] )
|| 'nexus2 Fact_VisiteretTid'[Stop] >= MAX ( Dato[Dato] )
)
)
RETURN
CALCULATE(
COUNTROWS( _Table),
CROSSFILTER ( 'nexus2 Fact_VisiteretTid'[Start], Dato[Dato], NONE )
)
Not sure if that will make a difference, but you can check the steps by using the return function firstly to see what the VAR returns (using COUNTROWS) and see if it makes sense, and then check the impact of the second filter expression in the final CALCULATE function.
Make sense?