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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
MightyMicrobe
Helper II
Helper II

Measure for Previous Week Based on Index

Hi all, I have a table with a numeric index indicating Weeks Back from today. 

 
 

I need to create a measure indicating the value of the previous week, based on the index. 

I can successfully do it in a column, using the formula below, but I want to do it as a measure. 

 

image.png

I tried building it with Quick measures, but only seem to be able to do it from week 0. How do I modify the formula below so that it references the previous week instead of week zero? Thank you!

 

image.png

6 REPLIES 6
Tahreem24
Super User
Super User

@MightyMicrobe ,

 

If you want it to use in measure so use MAX instead of EARLIER. Because EARLIER is not supported in measure.

 

 

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

Yes, this is the bit that threw me -- I didn't think of using MAX/MIN instead of EARLIER. 

 

My final formula is this:

Total User Previous Period = 
CALCULATE([Total Users], 
FILTER(ALL('Asset Customer Activity'), 'Asset Customer Activity'[Weeks Back]=MIN('Asset Customer Activity'[Weeks Back])+1))
 
I do have a calendar table, but for this particular query I'm using the index already there (long story). 
amitchandak
Super User
Super User

@MightyMicrobe , refer to my blog , how to deal with week

https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...

 

This Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

 

Using

Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Number = WEEKNUM([Date],2)
Week = if('Date'[Week Number]<10,'Date'[Year]*10 & 'Date'[Week Number],'Date'[Year]&'Date'[Week Number])
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
Week name = [Week Start date] & " to "& [Week End date]
Weekday = WEEKDAY([Date],2)
WeekDay Name = FORMAT([Date],"ddd")

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

 

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

@amitchandak Thank you for your help, this formula works. 

 

I have a further question if you don't mind. I'm trying to use this formula (the previous week results) in a KPI visualisation. The report has some slicers/filters. They apply to the main data label of the visualization, but not to the previous week's results based on your formula. 

 

Can you give a hint on how to modify the formula so that it references the filters on the page or at the viz level?

Total User Previous Period = 
CALCULATE([Total Users], 
FILTER(ALL('Asset Customer Activity'), 'Asset Customer Activity'[Weeks Back]=MIN('Asset Customer Activity'[Weeks Back])+1))

 

image.png

MightyMicrobe
Helper II
Helper II

This is my data:

image.png

So typically you do this using ADDCOLUMNS like:

 

Measure = 

VAR __Table = ADDCOLUMNS('Table',"Previous",<your column formula goes here>)

RETURN

<some operation across __Table>

 

If that is not enough detail for you. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

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.