Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
KNW
Regular Visitor

VAR in Filter issue

Hi,

 

So I am trying to use VAR in a filter and came across this issue:

Why this:

 

Phone = COUNTAX (
    FILTER (
        'table',
        ( LEFT ( 'table'[group_name], 20 ) = "XXXXXXXXXX" )
            && ( LEFT ( 'table'[2ndgroup_name], 20 ) = "XXXXXXXXXX" )
            && 'table'[reas_count] = 0
            && 'table'[type] = "Phone"
            ),
    'table'[number])
 
is not equal to this:
 
Phone2 =
VAR _LEFT = COUNTAX(FILTER('table', (LEFT ( 'table'[group_name], 20 ) = "XXXXXXXXXX")
            && (LEFT ( 'table'[2ndgroup_name], 20 ) = "XXXXXXXXXX") && 'table'[reas_count] = 0), 'table'[number])
RETURN
COUNTAX(FILTER('table', _LEFT && [type] = "Phone"), 'table'[number])
 
Only the first DAX measure counts correctly but i would like to use VAR because that DAX measure uses filters from _LEFT few times and I want it to be calculated only once to improve performance. _LEFT is filtering the table correctly but when the second condition [type]="Phone" is added then rows that contain "Phone" are counted without those conditions specified in _LEFT.
Is it even possible to use VAR in a filter?
1 ACCEPTED SOLUTION

well that totally makes sense now. 
if var has to be scalar then there is no way it would work.
thanks for having a look into it, that's what i needed.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Can you please share the Power bi file?
Based upon your post and my understanding, the variable _LEFT will be storing a number and what you are trying to perform in the 2nd measure after RETURN is that :
You are trying to filter the table ie. Filter( Table, _LEFT && [type]="Phone")
_LEFT is storing a number. So as per me it does not makes any sense in the filter part. If _LEFT is 0, it would be taking false and if it is 1 it would be taking 1. (This is my understanding)

I am not sure about the answer and I might be wrong.

well that totally makes sense now. 
if var has to be scalar then there is no way it would work.
thanks for having a look into it, that's what i needed.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.