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
heidibb
Helper IV
Helper IV

Create column with Earlier value from another row

Hello,

 

I have a data table similar to this (the first three columns). I would like to create a column that pulls in the previous week's date. I think from my research I should use the EARLIER function, but I'm not sure how to structure the formula. So, for each ID and week, I need to get the date for the previous week for the same ID.

 

Any thoughts?

 

Capture.JPG

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @heidibb,

 

If I understand you correctly, you should be able to use the formula below to create a column that pulls in the previous week's date in your scenario. Smiley Happy

Previous Week Date = 
CALCULATE (
    MAX ( Table1[Date] ),
    FILTER (
        ALL ( Table1 ),
        Table1[ID] = EARLIER ( Table1[ID] )
            && Table1[Week]
                = EARLIER ( Table1[Week] ) - 1
    )
)

c1.PNG

 

Regards

View solution in original post

3 REPLIES 3
v-ljerr-msft
Employee
Employee

Hi @heidibb,

 

If I understand you correctly, you should be able to use the formula below to create a column that pulls in the previous week's date in your scenario. Smiley Happy

Previous Week Date = 
CALCULATE (
    MAX ( Table1[Date] ),
    FILTER (
        ALL ( Table1 ),
        Table1[ID] = EARLIER ( Table1[ID] )
            && Table1[Week]
                = EARLIER ( Table1[Week] ) - 1
    )
)

c1.PNG

 

Regards

TomMartens
Super User
Super User

Hey,

 

here is a part of my calendar already with the column you want to create "prevDate"

2017-08-17_23-09-58.png

 

The column "Month Year" corresponds to your column "ID" and the column "Day of Month" to your column "Week" and here is the DAX statement

 

prevDate = 
var currentGroup = calculate(max('Calendar'[Month Year]))
var currentDayIndex = calculate(max('Calendar'[Day Of Month]))
return
LOOKUPVALUE('Calendar'[Date], 'Calendar'[Month Year], currentGroup, 'Calendar'[Day Of Month], currentDayIndex -1)

I'm storing the column values of the current row into variables and then use these variables inside the LOOKUPVALUE function to retrieve the Date column by adjusting the currentDayIndex value with -1.

 

Hope this helps

 

Regards



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
heidibb
Helper IV
Helper IV

As I continue to research, I wonder if LookupValue is a better function. Still unsure how to structure the formula since i need the previous week's date at the ID level.

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