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

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

Reply
Anonymous
Not applicable

Calculating previous values

A super user - smpa01 has helped me previously with this but I need additional help.. 

 

I am trying to calculate values for "Net Hires" the last two weeks, as you can see in my screen shot (the calculation is showing wrong because, I assume, it does not consider the newly added colums - Region and location) 

 

UnknownValue_0-1643055698023.png

How do I ensure that when the page is being filtered, values from this measure change accordingly? I have few additional columns (Location and Region) in the dataset can be filtered by but I cannot figure out where I should add them to the statement. Are you able to help me?

 

Last 2 Weeks =

VAR week = MAXA( 'Terms & Hires SQL'[Fiscal Week Ends])
VAR cal = CALCULATE (SUM ( 'Terms & Hires SQL'[Net Hires]),
 
FILTER (ALL ('Terms & Hires SQL'),
'Terms & Hires SQL'[Fiscal Week Ends]
>= CALCULATE ( MAXA ( 'Terms & Hires SQL'[Fiscal Week Ends] ), 'Terms & Hires SQL'[Fiscal Week Ends] < week, ALL ('Terms & Hires SQL') )
&& 'Terms & Hires SQL'[Fiscal Week Ends] <= week))
RETURN
cal
 
Data Sample: 
Location Table SQL.DivisionLocationFiscal Week BeginsFiscal Week EndsFiscal Week NumHire_CountTerm_CountNet Hires
WEST1012/25/2021 0:0012/31/2021 0:004802-2
WEST111/1/2022 0:001/7/2022 0:004903-3
WEST121/8/2022 0:001/14/2022 0:0050101
WEST101/15/2022 0:001/21/2022 0:0051413
WEST101/22/2022 0:001/28/2022 0:0052211
WEST101/29/2022 0:002/4/2022 0:00101-1
WEST102/5/2022 0:002/11/2022 0:002101
WEST105012/25/2021 0:0012/31/2021 0:004812-1
WEST501/1/2022 0:001/7/2022 0:004902-2
8 REPLIES 8
VahidDM
Super User
Super User

HI @Anonymous 

 

You used ALL in the formula that blocked all filters, try this:

 

Last 2 Weeks =
VAR _W1 =
    MAXA ( 'Terms & Hires SQL'[Fiscal Week Ends] )
VAR _W2 =
    CALCULATE (
        MAXA ( 'Terms & Hires SQL'[Fiscal Week Ends] ),
        FILTER (
            ALL ( 'Terms & Hires SQL' ),
            'Terms & Hires SQL'[Fiscal Week Ends] < week
        )
    )
VAR cal =
    CALCULATE (
        SUM ( 'Terms & Hires SQL'[Net Hires] ),
        FILTER (
            ALL ( 'Terms & Hires SQL'[Net Hires] ),
            'Terms & Hires SQL'[Fiscal Week Ends] >= _W2
                && 'Terms & Hires SQL'[Fiscal Week Ends] <= _W1
        )
    )
RETURN
    cal

 

https://docs.microsoft.com/en-us/dax/all-function-dax

 

Check this :  https://www.vahiddm.com/post/weekly-time-intelligence-dax

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Anonymous
Not applicable

@VahidDM does not seem to work, trying to tinker with it now...

 

Last 2 Weeks =

VAR _W1 =

    MAXA ( 'Terms & Hires SQL'[Fiscal Week Ends] )

VAR _W2 =

    CALCULATE (

        MAXA ( 'Terms & Hires SQL'[Fiscal Week Ends] ),

        FILTER (

            ALL ( 'Terms & Hires SQL' ),

            'Terms & Hires SQL'[Fiscal Week Ends] < week (This only lets me enter in _W1 as the variable)

        )

    )

VAR cal =

    CALCULATE (

        SUM ( 'Terms & Hires SQL'[Net Hires] ),

        FILTER (

            ALL ( 'Terms & Hires SQL'[Net Hires] ),

            'Terms & Hires SQL'[Fiscal Week Ends] >= _W2

                && 'Terms & Hires SQL'[Fiscal Week Ends] <= _W1

        )

    )

RETURN

    cal

@Anonymous 

 

My bad! try this:

Last 2 Weeks =
VAR _W1 =
    MAXA ( 'Terms & Hires SQL'[Fiscal Week Ends] )
VAR _W2 =
    CALCULATE (
        MAXA ( 'Terms & Hires SQL'[Fiscal Week Ends] ),
        FILTER (
            ALL ( 'Terms & Hires SQL' ),
            'Terms & Hires SQL'[Fiscal Week Ends] < _W1
        )
    )
VAR cal =
    CALCULATE (
        SUM ( 'Terms & Hires SQL'[Net Hires] ),
        FILTER (
            ALL ( 'Terms & Hires SQL'[Net Hires] ),
            'Terms & Hires SQL'[Fiscal Week Ends] >= _W2
                && 'Terms & Hires SQL'[Fiscal Week Ends] <= _W1
        )
    )
RETURN
    cal

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Anonymous
Not applicable

Does not seem to work 

 

UnknownValue_0-1643666084362.png

 

@Anonymous 

 

Can you share your PBIX file with me?

Share that on https://wetransfer.com/ and past the link here


Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

 

 

Anonymous
Not applicable

I cannot, I am sorry, it's all coming from SQL and  there is a lot of sensitve data but here is a sample of the data 

 

Location Table SQL.DivisionLocationFiscal Week BeginsFiscal Week EndsFiscal Week NumHire_CountTerm_CountNet Hires
WEST1012/25/2021 0:0012/31/2021 0:004802-2
WEST111/1/2022 0:001/7/2022 0:004903-3
WEST121/8/2022 0:001/14/2022 0:0050101
WEST101/15/2022 0:001/21/2022 0:0051413
WEST101/22/2022 0:001/28/2022 0:0052211
WEST101/29/2022 0:002/4/2022 0:00101-1
WEST102/5/2022 0:002/11/2022 0:002101
WEST105012/25/2021 0:0012/31/2021 0:004812-1
WEST501/1/2022 0:001/7/2022 0:004902-2

Hi @Anonymous 

 

Try this:

Last 2 Weeks = 
VAR _W1 =
    MAX ( 'Terms & Hires SQL'[Fiscal Week Ends] )
VAR _W2 =
    CALCULATE (
        MAX ( 'Terms & Hires SQL'[Fiscal Week Ends] ),
        FILTER (
            ALL ( 'Terms & Hires SQL' ),
            'Terms & Hires SQL'[Fiscal Week Ends] < _W1
        )
    )
VAR cal =
    CALCULATE (
        SUM ( 'Terms & Hires SQL'[Net Hires] ),
        FILTER (
            ALL ( 'Terms & Hires SQL'),
            'Terms & Hires SQL'[Fiscal Week Ends] >= _W2
                && 'Terms & Hires SQL'[Fiscal Week Ends] <= _W1
        )
    )
RETURN
    _W2

 

In your sample Data the result is zero (11-Feb net Hire is 1 and 4-Feb it's -1)

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Anonymous
Not applicable

It's a date and if created as a new column and formatted as a number the values are the same 

 

UnknownValue_0-1643722818815.png

 

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.