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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.