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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Calculated Column

I have been tasked to create a measure that will show total revenue - 2 week revenue and another for total revenue and 4 weeks ago. I have these measures created already but the problem is they want these measures to popluate with a date slicer and I don't know how to do that can you help me.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

 

Thank you very much sevenhills and Power2G for your prompt reply.

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"Sales"

vnuocmsft_0-1738737355301.png

 

Ensure you have a Date table in your model.

DateTable = CALENDAR(MIN('Sales'[Date]), MAX('Sales'[Date]))

 

Create measures.

Revenue2WeeksAgo = 
VAR DataWeekNUM = WEEKNUM(MAX('DateTable'[Date]))
RETURN
CALCULATE(
    SUM('Sales'[Revenue]),
    FILTER(
        ALL('Sales'),
        WEEKNUM('Sales'[Date]) < DataWeekNUM
        &&
        WEEKNUM('Sales'[Date]) >= DataWeekNUM - 2
    )
)

 

Revenue4WeeksAgo = 
VAR DataWeekNUM = WEEKNUM(MAX('DateTable'[Date]))
RETURN
CALCULATE(
    SUM('Sales'[Revenue]),
    FILTER(
        ALL('Sales'),
        WEEKNUM('Sales'[Date]) < DataWeekNUM
        &&
        WEEKNUM('Sales'[Date]) >= DataWeekNUM - 4
    )
)

 

Here is the result.

 

vnuocmsft_1-1738737642100.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous 

 

Thank you very much sevenhills and Power2G for your prompt reply.

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"Sales"

vnuocmsft_0-1738737355301.png

 

Ensure you have a Date table in your model.

DateTable = CALENDAR(MIN('Sales'[Date]), MAX('Sales'[Date]))

 

Create measures.

Revenue2WeeksAgo = 
VAR DataWeekNUM = WEEKNUM(MAX('DateTable'[Date]))
RETURN
CALCULATE(
    SUM('Sales'[Revenue]),
    FILTER(
        ALL('Sales'),
        WEEKNUM('Sales'[Date]) < DataWeekNUM
        &&
        WEEKNUM('Sales'[Date]) >= DataWeekNUM - 2
    )
)

 

Revenue4WeeksAgo = 
VAR DataWeekNUM = WEEKNUM(MAX('DateTable'[Date]))
RETURN
CALCULATE(
    SUM('Sales'[Revenue]),
    FILTER(
        ALL('Sales'),
        WEEKNUM('Sales'[Date]) < DataWeekNUM
        &&
        WEEKNUM('Sales'[Date]) >= DataWeekNUM - 4
    )
)

 

Here is the result.

 

vnuocmsft_1-1738737642100.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

sevenhills
Super User
Super User

I think your post title says Calculated Column and you are asking for measures! This is minor point.

 

Let us go through your requirements

1. You already have [Total Revenue], [Total Revenue - 2 W], [Total Revenue - 4 W] measures

 

2. You want to adjust based on a date slicer.

 

You can do these:

1. Create a slicer using your date table 

sevenhills_0-1738778298788.png

 

2. Adjust the measures, let u do one and then you can do the other similar way by adjusting -14 as -28.

 

 

 

 

[Total Revenue - 2 W] =
VAR _SelDate =
    IF (
        ISFILTERED ( 'DateTable'[Date] ),
        MAX( 'DateTable'[Date] ),
         BLANK()  
    )
RETURN  IF( ISBLANK( SUM(Sales[Revenue])  ) || ISBLANK( _SelDate ) || NOT HASONEVALUE('DateTable'[Date]), BLANK(), 
    CALCULATE (
        SUM ( 'Sales'[Revenue] ),
        DATESINPERIOD(  Sales[Date], _SelDate, -14, DAY )
    )
)
        
 

 

 

 

3. For testing add 2 dummy measures and remove after your testing

 

 

Total Revenue - 2 W - Min Date = 
VAR _SelDate =
    IF (
        ISFILTERED ( 'DateTable'[Date] ),
        MAX( 'DateTable'[Date] ),
        BLANK()  
    )
RETURN  minx(  DATESINPERIOD(  'DateTable'[Date], _SelDate, -14, DAY ) , 'DateTable'[Date])

 

 

 

Total Revenue - 2 W - Max Date = 
VAR _SelDate =
    IF (
        ISFILTERED ( 'DateTable'[Date] ),
        MAX( 'DateTable'[Date] ),
        BLANK()  
    )
RETURN  maxx(  DATESINPERIOD(  'DateTable'[Date], _SelDate, -14, DAY ) , 'DateTable'[Date])

 

 

Sample from adventure works:

sevenhills_1-1738778501694.png

 

 

 Hope it helps!

Power2G
Frequent Visitor

To beging, make sure you have a proper date table in your data model and create relationships between your Sales[Date] and the Date table.

First measure

TotalRevenue = SUM(Sales[Revenue])

Second measure

RevenueLast2Weeks = 
CALCULATE(
    [TotalRevenue],
    DATESINPERIOD(
        Sales[Date],
        MAX(Sales[Date]),
        -2,
        WEEK
    )
)

Third measure

RevenueLast4Weeks = 
CALCULATE(
    [TotalRevenue],
    DATESINPERIOD(
        Sales[Date],
        MAX(Sales[Date]),
        -4,
        WEEK
    )
)

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors