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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
PBI_newuser
Post Prodigy
Post Prodigy

How to lookup last week data to the same table?

Hi,

I have a table as below (Table A):
How can I lookup last week difference by using Material in the same table? (Refer to Output Table below)

 

Table A:

DateMaterialSales Qty Repair QtyDifference (Sales-Repair)
31/12/2020M-1562135
7/1/2021M-7231112
14/1/2021M-41239
21/1/2021M-1993267
28/1/2021M-2342212
4/2/2021M-3321517

 

Output Table:

DateMaterialSales Qty Repair QtyDifference (Sales-Repair)Difference last week
31/12/2020M-1562135-
7/1/2021M-723111235
14/1/2021M-4123912
21/1/2021M-19932679
28/1/2021M-234221267
4/2/2021M-332151712

 

1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi, @PBI_newuser 

Solution 1 You can create a Calculated column to get the result you want.

 

SAP-FSL LW =

VAR _preweek =

    CALCULATE (

        MAX ( 'Sample Data'[Date] ),

        FILTER (

            ALL ( 'Sample Data' ),

            'Sample Data'[Material&Location] = EARLIER ( 'Sample Data'[Material&Location] )

                && 'Sample Data'[Date] < EARLIER ( 'Sample Data'[Date] )

        )

    )

VAR _presqty =

    CALCULATE (

        MAX ( 'Sample Data'[SAP Qty] ),

        FILTER (

            ALL ( 'Sample Data' ),

            'Sample Data'[Material&Location] = EARLIER ( 'Sample Data'[Material&Location] )

                && 'Sample Data'[Date] = _preweek

        )

    )

VAR _prefqty =

    CALCULATE (

        MAX ( 'Sample Data'[FSL Qty] ),

        FILTER (

            ALL ( 'Sample Data' ),

            'Sample Data'[Material&Location] = EARLIER ( 'Sample Data'[Material&Location] )

                && 'Sample Data'[Date] = _preweek

        )

    )

VAR result = _presqty - _prefqty

RETURN

    IF ( ISBLANK ( result ), "-", FORMAT ( result, "" ) )

 

 

Solution 2 You can also create a Measure.

Measure For SAP-FSL LW =

VAR _curdate =

    MAX ( 'Sample Data'[Date] )

VAR _curmaloc =

    MAX ( 'Sample Data'[Material&Location] )

VAR _preweek =

    CALCULATE (

        MAX ( 'Sample Data'[Date] ),

        FILTER (

            ALL ( 'Sample Data' ),

            'Sample Data'[Material&Location] = _curmaloc

                && 'Sample Data'[Date] < _curdate

        )

    )

VAR _presqty =

    CALCULATE (

        MAX ( 'Sample Data'[SAP Qty] ),

        FILTER (

            ALL ( 'Sample Data' ),

            'Sample Data'[Material&Location] = _curmaloc

                && 'Sample Data'[Date] = _preweek

        )

    )

VAR _prefqty =

    CALCULATE (

        MAX ( 'Sample Data'[FSL Qty] ),

        FILTER (

            ALL ( 'Sample Data' ),

            'Sample Data'[Material&Location] = _curmaloc

                && 'Sample Data'[Date] = _preweek

        )

    )

VAR result = _presqty - _prefqty

RETURN

    IF ( ISBLANK ( result ), "-", result )

 

 

The result looks like this:

v-cazheng-msft_0-1611037545355.jpeg

 

 

Here is the sample.

 

Best Regards,

Caiyun Zheng

 

Is that the answer you're looking for? 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

4 REPLIES 4
v-cazheng-msft
Community Support
Community Support

Hi, @PBI_newuser 

Solution 1 You can create a Calculated column to get the result you want.

 

SAP-FSL LW =

VAR _preweek =

    CALCULATE (

        MAX ( 'Sample Data'[Date] ),

        FILTER (

            ALL ( 'Sample Data' ),

            'Sample Data'[Material&Location] = EARLIER ( 'Sample Data'[Material&Location] )

                && 'Sample Data'[Date] < EARLIER ( 'Sample Data'[Date] )

        )

    )

VAR _presqty =

    CALCULATE (

        MAX ( 'Sample Data'[SAP Qty] ),

        FILTER (

            ALL ( 'Sample Data' ),

            'Sample Data'[Material&Location] = EARLIER ( 'Sample Data'[Material&Location] )

                && 'Sample Data'[Date] = _preweek

        )

    )

VAR _prefqty =

    CALCULATE (

        MAX ( 'Sample Data'[FSL Qty] ),

        FILTER (

            ALL ( 'Sample Data' ),

            'Sample Data'[Material&Location] = EARLIER ( 'Sample Data'[Material&Location] )

                && 'Sample Data'[Date] = _preweek

        )

    )

VAR result = _presqty - _prefqty

RETURN

    IF ( ISBLANK ( result ), "-", FORMAT ( result, "" ) )

 

 

Solution 2 You can also create a Measure.

Measure For SAP-FSL LW =

VAR _curdate =

    MAX ( 'Sample Data'[Date] )

VAR _curmaloc =

    MAX ( 'Sample Data'[Material&Location] )

VAR _preweek =

    CALCULATE (

        MAX ( 'Sample Data'[Date] ),

        FILTER (

            ALL ( 'Sample Data' ),

            'Sample Data'[Material&Location] = _curmaloc

                && 'Sample Data'[Date] < _curdate

        )

    )

VAR _presqty =

    CALCULATE (

        MAX ( 'Sample Data'[SAP Qty] ),

        FILTER (

            ALL ( 'Sample Data' ),

            'Sample Data'[Material&Location] = _curmaloc

                && 'Sample Data'[Date] = _preweek

        )

    )

VAR _prefqty =

    CALCULATE (

        MAX ( 'Sample Data'[FSL Qty] ),

        FILTER (

            ALL ( 'Sample Data' ),

            'Sample Data'[Material&Location] = _curmaloc

                && 'Sample Data'[Date] = _preweek

        )

    )

VAR result = _presqty - _prefqty

RETURN

    IF ( ISBLANK ( result ), "-", result )

 

 

The result looks like this:

v-cazheng-msft_0-1611037545355.jpeg

 

 

Here is the sample.

 

Best Regards,

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-cazheng-msft Thank you so much for the solution! 🙂

amitchandak
Super User
Super User

@PBI_newuser , for a new column try like

maxx(filter(Table, [Date] = earlier([Date]) -7),[Difference (Sales-Repair)])

 

For measure refer my blog

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak 

The column created is incorrect. You may see below the LW (last week) figure is lookup wrongly.

Please help. Below is the sample data for your reference.

https://wetransfer.com/downloads/7f1536d9be35219918f83e28f92af05120210115052823/a3b7ab18c55ba817bce0...

 

PBI_newuser_1-1610684368969.png

 

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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!

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.

Top Solution Authors
Top Kudoed Authors