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
Anonymous
Not applicable

Calculating value for last two weeks

Hello, 

 

I have a dataset with fiscal weeks, here is a sample: 

Fiscal YearFiscal WeekNet HiresNet Hires Previous Two WeeksDate
202148100

 

12/27/2021

2021495015001/03/2022
20215015020001/10/2022
2021513018001/17/2022

 

How do I calculate the total of net hires for the last two fiscal weeks from today? The last column shows what I am after.

I assume I first need to figure out what today is, what fiscal week it is in and then what are the two fiscal weeks from today?

 

 

1 ACCEPTED SOLUTION
smpa01
Super User
Super User

@Anonymous  you can use a measure like this

Measure = 
VAR week =
    MAX ( tbl[Fiscal Week] )
VAR cal =
    CALCULATE (
        SUM ( tbl[Net Hires] ),
        FILTER (
            ALL ( tbl ),
            tbl[Fiscal Week]
                >= CALCULATE ( MAX ( tbl[Fiscal Week] ), tbl[Fiscal Week] < week, ALL ( tbl ) )
                && tbl[Fiscal Week] <= week
        )
    )
RETURN
    cal

 

 

smpa01_0-1642453887055.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Thank you SOOOOOOOOOOO much!

smpa01
Super User
Super User

@Anonymous  you can use a measure like this

Measure = 
VAR week =
    MAX ( tbl[Fiscal Week] )
VAR cal =
    CALCULATE (
        SUM ( tbl[Net Hires] ),
        FILTER (
            ALL ( tbl ),
            tbl[Fiscal Week]
                >= CALCULATE ( MAX ( tbl[Fiscal Week] ), tbl[Fiscal Week] < week, ALL ( tbl ) )
                && tbl[Fiscal Week] <= week
        )
    )
RETURN
    cal

 

 

smpa01_0-1642453887055.png

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

Hi @smpa01,

 

I adjusted the statement a little bit to fit my everchanging dataset, how do I ensure that when the page is being filtered, values from this measure change accordingly? I have few additional columns 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?

Capture.PNG

 

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
Anonymous
Not applicable

Thank you SOOOOOO much!

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.

Top Solution Authors
Top Kudoed Authors