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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
Anonymous
Not applicable

Question about Variables (VAR)

Hi!
I have a calculated table that tells me if the client has sold more than 25K in the last 3 Quarters.

When I use variables, it doesn't work, when I don't use variables, it does....
Why??? It looks ugly without the variables...
With Variables:

Normalize = 
VAR Qm1 =
    CALCULATE (
        [SO Net],
        PREVIOUSQUARTER ( LASTDATE ( 'DB'[Date] ) )
    )
VAR Qm2 =
    CALCULATE (
        [SO Net],
        PREVIOUSQUARTER ( PREVIOUSQUARTER ( LASTDATE ( 'DB'[Date] ) ) )
    )
VAR Qm3 =
    CALCULATE (
        [SO Net],
        PREVIOUSQUARTER (
            PREVIOUSQUARTER ( PREVIOUSQUARTER ( LASTDATE ( 'DB'[Date] ) ) )
        )
    )
RETURN
        SUMMARIZECOLUMNS('DB'[End User Name (or Next Purchasing Entity)],
        "Normalize",
            SWITCH (
                TRUE (),
                CALCULATE (
        [SO Net],
        PREVIOUSQUARTER ( LASTDATE ( 'DB'[Date] ) )
    ) > 25000
                    && CALCULATE (
        [SO Net],
        PREVIOUSQUARTER ( PREVIOUSQUARTER ( LASTDATE ( 'DB'[Date] ) ) )
    ) > 25000
                    && CALCULATE (
        [SO Net],
        PREVIOUSQUARTER (
            PREVIOUSQUARTER ( PREVIOUSQUARTER ( LASTDATE ( 'DB'[Date] ) ) )
        )
    ) > 25000, "Large Clients (Exclude to normalize)",
                "Other Clients"
            )
    )

 

 Without Variables:

Normalize = 
SUMMARIZECOLUMNS (
    'DB'[End User Name (or Next Purchasing Entity)],
    "Normalize",
        SWITCH (
            TRUE (),
            CALCULATE ( [SO Net], PREVIOUSQUARTER ( LASTDATE ( 'DB'[Date] ) ) ) > 25000
                && CALCULATE (
                    [SO Net],
                    PREVIOUSQUARTER ( PREVIOUSQUARTER ( LASTDATE ( 'DB'[Date] ) ) )
                ) > 25000
                && CALCULATE (
                    [SO Net],
                    PREVIOUSQUARTER (
                        PREVIOUSQUARTER ( PREVIOUSQUARTER ( LASTDATE ( 'DB'[Date] ) ) )
                    )
                ) > 25000, "Large Clients (Exclude to normalize)",
            "Other CLients"
        )
)
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

Looking at the two measures you wrote separately (with and without variables), the first measure with variables, although variables are defined, but does not use it in the later calculations. It seems that the formulas are the same except for the defined variable in these two measures. It is reasonable to assume that the two measures will return the same results...
You can check the following link to learn more about the use and caution of variables. Variables are calculated within the scope in which they are written, and then the result of them is stored and used in the rest of the expression.

Use variables to improve your DAX formulas

Caution When Using Variables in DAX and Power BI

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Anonymous ,

Looking at the two measures you wrote separately (with and without variables), the first measure with variables, although variables are defined, but does not use it in the later calculations. It seems that the formulas are the same except for the defined variable in these two measures. It is reasonable to assume that the two measures will return the same results...
You can check the following link to learn more about the use and caution of variables. Variables are calculated within the scope in which they are written, and then the result of them is stored and used in the rest of the expression.

Use variables to improve your DAX formulas

Caution When Using Variables in DAX and Power BI

Best Regards

lbendlin
Super User
Super User

You are defining the variables but are not using them anywhere?

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.