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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
PeraZo
Helper I
Helper I

How to create new column that get value from previous row (previous date)

Hi,

 

Can someone kindly help me adding new column ("Sales Previous Day ") that gets value from previous row (or previpus day, week, year)?

 

The table data is below.

I want to get sales number of the previous days, weeks, years for each "Store ID".

 

IDStore IDDateSalesSales Previous Day (or week or month)
112021/06/18369 
222021/06/18800 
332021/06/18700 
412021/06/19400369
522021/06/19850800
632021/06/19750700
712021/06/20500400

 

I don't want to do this using DAX like sameperiod previous month, dateadd but show in new column as I want to calculate each row.

 

I tried to use custom columns and Date.Add function but coundn't reach the solution. 

 

Thank you.

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@PeraZo 

You can try this as a new column:

Previous Day Sales = 

CALCULATE(
    SUM(Table2[Sales]),
    LASTDATE(
    FILTER(
        ALL(Table2[Date] ),
        Table2[Date] < EARLIER([Date]) 
        )
    ), 
    ALLEXCEPT(Table2,Table2[Store ID])
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
PeraZo
Helper I
Helper I

Hi,

 

Thank you!!

It worked.

 

I customized your code like below for previous week, month etc. and it's working. 

 

Previous Week Sales = 

CALCULATE(
    SUM(Table2[Sales]),
    LASTDATE(
    FILTER(
        ALL(Table2[Date] ),
        Table2[Date] < EARLIER([Date]) -6
        )
    ), 
    ALLEXCEPT(Table2,Table2[Store ID])
)

 

Thank you.

Cheers.

Fowmy
Super User
Super User

@PeraZo 

You can try this as a new column:

Previous Day Sales = 

CALCULATE(
    SUM(Table2[Sales]),
    LASTDATE(
    FILTER(
        ALL(Table2[Date] ),
        Table2[Date] < EARLIER([Date]) 
        )
    ), 
    ALLEXCEPT(Table2,Table2[Store ID])
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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