Forum Discussion

Fcoatis's avatar
Fcoatis
Icon for Post Patron rankPost Patron
5 years ago

Scope of Variable

Hello,

I got the result I wanted, however using two measures. What I would like to get is the same result using just one.

Here is the result achieved.

 

The Total returns the right sum of whatever is filtered in 'Bins'. But here is the two measure way:

Count Bins = 
VAR _min =  SELECTEDVALUE( Bins[min])
VAR _max =  SELECTEDVALUE( Bins[max])
VAR Res =
COUNTROWS(
    FILTER(Base,
        Base[Value] >= _min && Base[Value] < _max
    )
)
RETURN
IF(HASONEFILTER(Bins[Bins]),Res,False())

 First created Count Bins measure, then this one: (which is used in the table)

Count = IF(HASONEFILTER(Bins[Bins]),[Count Bins],SUMX(Bins,[Count Bins]))

 But what I tried to do was:

Count Bins = 
VAR _min =  SELECTEDVALUE( Bins[min])
VAR _max =  SELECTEDVALUE( Bins[max])
VAR Res =
COUNTROWS(
    FILTER(Base,
        Base[Value] >= _min && Base[Value] < _max
    )
)
RETURN
IF(HASONEFILTER(Bins[Bins]),Res,SUMX(Bins,Res))

 Obviously getting no result in Total. I´m not seeing the obvious. Is there a way withou using virtual table?

 

Thanks in advance

3 Replies