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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kkanda
Resolver I
Resolver I

Use of multiple variables in the same measure

Hi All,

I have gone through the some related posts in this Forum and SQL BI and I wrote the following DAX expression using multiple variables for the measure:

Test_Measure =
Var Res_2 = FILTER('M1 Notifications', ('M1 Notifications'[Created on] < (TODAY()-1825) && 'M1 Notifications'[Created on] > (TODAY()-365))
Var Res_1 = FILTER(Res_2, ('M1 Notifications'[Notification System Status] = "Outstanding notification" || 'M1 Notifications'[Notification System Status] = "Order assigned" || 'M1 Notifications'[Notification System Status] = "Notification in process"))
RETURN
IF(COUNTROWS(Res_1) <> BLANK(),COUNTROWS(Res_1),UNICHAR((32))
)
I used two Variables to filter the same table in succession for different criteria. This is basically an AND filter.
I get a syntax error for Var Res_1. I am not sure how we can use both Variables instead of writing a long Filter expression combining all conditions. For Var Res_1, can I use the filtered table Res_2? I tried using table name in its place but it is still the same error.
I will appreciate if the experts explain how the successive filters can be applied with Variables.
Thank you in advance
Krishna
2 ACCEPTED SOLUTIONS
jdbuchanan71
Super User
Super User

@kkanda 

Your measure was missing a closing parenthisis in the first Var.

Test Measure =
VAR Res_2 =
    FILTER (
        'M1 Notifications',
         (
            'M1 Notifications'[Created on]
                < ( TODAY () - 1825 )
                && 'M1 Notifications'[Created on]
                    > ( TODAY () - 365 )
        )
    )
VAR Res_1 =
    FILTER (
        Res_2,
         ( 'M1 Notifications'[Notification System Status] = "Outstanding notification"
            || 'M1 Notifications'[Notification System Status] = "Order assigned"
            || 'M1 Notifications'[Notification System Status] = "Notification in process" )
    )
RETURN
    IF ( COUNTROWS ( Res_1 ) <> BLANK (), COUNTROWS ( Res_1 ), UNICHAR ( ( 32 ) ) )

View solution in original post

Thanks for the correction. 

View solution in original post

2 REPLIES 2
jdbuchanan71
Super User
Super User

@kkanda 

Your measure was missing a closing parenthisis in the first Var.

Test Measure =
VAR Res_2 =
    FILTER (
        'M1 Notifications',
         (
            'M1 Notifications'[Created on]
                < ( TODAY () - 1825 )
                && 'M1 Notifications'[Created on]
                    > ( TODAY () - 365 )
        )
    )
VAR Res_1 =
    FILTER (
        Res_2,
         ( 'M1 Notifications'[Notification System Status] = "Outstanding notification"
            || 'M1 Notifications'[Notification System Status] = "Order assigned"
            || 'M1 Notifications'[Notification System Status] = "Notification in process" )
    )
RETURN
    IF ( COUNTROWS ( Res_1 ) <> BLANK (), COUNTROWS ( Res_1 ), UNICHAR ( ( 32 ) ) )

Thanks for the correction. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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