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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
gwaczoka
Regular Visitor

How to get new column with value from previous date (with additional conditions)

Hi,

I have a table, here is the example:

gwaczoka_0-1666270836966.png

 

I'd like to add a new column which I don't know how to get (last one called "Prev day flag"

Explanation:

I have a table with lists of products (Item ID) and suppliers for each product.

Everyday I have a different flag for this product and I want to know what was the flag previous day. Not always days are +1, sometime it is +7, so then I want to know what was the flag  7 days ago

 

I tried to use CALCULATE + EARLIER function, but it doesn't work. As far as I know, we use calculate with metrics, but here I need a column...

 

Please help!:) 

1 ACCEPTED SOLUTION
speedramps
Super User
Super User

Thanks for the data.

Try this ..

Click here to download solution

 

Current =
SELECTEDVALUE('Table'[Product flag])

 

Previous =
VAR mydate = SELECTEDVALUE('Table'[Date])
VAR myflag = SELECTEDVALUE('Table'[Product flag])
VAR previousdate = CALCULATE(MAX('Table'[Date]),ALL(), 'Table'[Date] < mydate)
VAR previousflag = CALCULATE(SELECTEDVALUE('Table'[Product flag]),'Table'[Date] = previousdate )
RETURN
previousflag

 

speedramps_0-1666276208642.png

 

Thanks for reaching out for help.

I put in a lot of effort to help you, now please quickly help me by giving kudos.

Remember we are unpaid volunteers and here to coach you with Power BI and DAX skills and techniques, not do the users job for them. So please click the thumbs up and accept as solution button. 

If you give someone a fish then you only give them one meal, but if you teach them how to fish then they can feed themselves and teach others for a lifetime.  I prefer to teach members on this forum techniques rather give full solutions and do their job. You can then adapt the technique for your solution, learn some DAX skills for next time and soon become a Power BI Super User like me. 

One question per ticket please. If you need to extend your request then please raise a new ticket.

You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you ! 

View solution in original post

5 REPLIES 5
speedramps
Super User
Super User

Thanks for the data.

Try this ..

Click here to download solution

 

Current =
SELECTEDVALUE('Table'[Product flag])

 

Previous =
VAR mydate = SELECTEDVALUE('Table'[Date])
VAR myflag = SELECTEDVALUE('Table'[Product flag])
VAR previousdate = CALCULATE(MAX('Table'[Date]),ALL(), 'Table'[Date] < mydate)
VAR previousflag = CALCULATE(SELECTEDVALUE('Table'[Product flag]),'Table'[Date] = previousdate )
RETURN
previousflag

 

speedramps_0-1666276208642.png

 

Thanks for reaching out for help.

I put in a lot of effort to help you, now please quickly help me by giving kudos.

Remember we are unpaid volunteers and here to coach you with Power BI and DAX skills and techniques, not do the users job for them. So please click the thumbs up and accept as solution button. 

If you give someone a fish then you only give them one meal, but if you teach them how to fish then they can feed themselves and teach others for a lifetime.  I prefer to teach members on this forum techniques rather give full solutions and do their job. You can then adapt the technique for your solution, learn some DAX skills for next time and soon become a Power BI Super User like me. 

One question per ticket please. If you need to extend your request then please raise a new ticket.

You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you ! 

Thank you for your response. It doesn't work when I apply that in my original table, I think that I'd need another condition with the supplier and itemid, because I have a lot of ITEM IDs and suppliers for one Item ID, and it should be in there I guess...

 

Remember we are unpaid volunteers. 😀
I provided a working example solution using the exmaple data you provided.

So I will close this problem.

One question per ticket please. If you need to extend or change your pronlem dessription then please raise a new ticket.0

You will get a quicker response and each volunteer solver will get the kudos they deserve. Thank you !

speedramps
Super User
Super User

Please provide example input data as table text (not a screen print) so we can import the data to build a solution for you.

DateItem IDSupplierProduct flag
01.01.2022ABCMaxdom0
02.01.2022ABCMaxdom

1

03.01.2022ABCMaxdom1
04.01.2022ABCAblax1
05.01.2022ABCAblax0
01.01.2022DEFPlot0
02.01.2022DEFPlot1
03.01.2022DEFPlot1
04.01.2022DEFPlot0

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.