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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
squiddly
Advocate I
Advocate I

Difference From Previous Week With Filters

I've seen similar topics but I think my case goes a bit further.  I have a database with about 3 million rows and growing of data.  There's a lot more to this data, but the relevent (and fuzzed) columns are here:

 

 image.png

 

Columns A thru D are in my data.  Column E shows what I'd like to show or calculate with Power BI.  I need to apply this logic to the calculation:

 

LastWeekComp = 	Lookup where Location = Location
		Lookup where IAVA = IAVA
		Lookup where Date = Date -7 days
		Return Compliant

And so the calculation of that final column would simply be

Difference From Previous Week = Compliant - LastWeekComp

I've seen lots of different suggestions for how to tackle this, and I've tried going down each one.  I just end up confusing myself.  Can any of you smart smart people help me down the right path?  Thank you so much for any insights!

1 ACCEPTED SOLUTION
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @squiddly

 

Please try adding this calculated column to your table.  Just replace the text 'Table1' with your own table name.  Remember to format the column as approprate.  

 

Column = 
VAR LastWeekComp = 
    SUMX(
        FILTER(
            'Table1',
            'Table1'[Location] = EARLIER('Table1'[Location]) &&
            'Table1'[Date] = EARLIER('Table1'[Date])-7  &&
            'Table1'[CVE] = EARLIER('Table1'[CVE])
            )
            ,'Table1'[Compliant])    
VAR Compliant = 'Table1'[Compliant]
RETURN  Compliant - LastWeekComp

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

4 REPLIES 4
Phil_Seamark
Microsoft Employee
Microsoft Employee

Hi @squiddly

 

Please try adding this calculated column to your table.  Just replace the text 'Table1' with your own table name.  Remember to format the column as approprate.  

 

Column = 
VAR LastWeekComp = 
    SUMX(
        FILTER(
            'Table1',
            'Table1'[Location] = EARLIER('Table1'[Location]) &&
            'Table1'[Date] = EARLIER('Table1'[Date])-7  &&
            'Table1'[CVE] = EARLIER('Table1'[CVE])
            )
            ,'Table1'[Compliant])    
VAR Compliant = 'Table1'[Compliant]
RETURN  Compliant - LastWeekComp

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

Thank you!! It works marvelously, now I can use slicer on this thing. 

Phil, you are so awesome.  I took this home to work on over a 3-day weekend and I was getting nowhere.

 

That code worked perfectly for my sample.  Will be implementing it this week at work.  Thanks so much!

parry2k
Super User
Super User

First foremost you need calendar table in your data model for any time based calculation, either it is previous month/week/year etc. You need to start with that then go from there. There are many posts on how to create calendar table in PowerBI which can get started you on that.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors