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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
New_be
Helper V
Helper V

Read previous rows from dates

Capture.PNG

Hi everyone! Im still new in power bi. Currently working on this project where i need to show the date for yesterday. For example in the image, if my date is 22/5/2020 (friday), i need to get the date for yesterday. But if my previous date have an off date, i need to get the value from all the off dates & from the day before it. Example if my date is 1/6/2020 (Monday), i need to get dates that takes from 29/5 until 31/5.  The logic is it will automatically count the OFF, and also take the previous date from the last OFF date.

I have 2 columns, DATE & DATE_OFF. Kindly need advice & ideas from the experts.

1 ACCEPTED SOLUTION

@New_be 

 

Try this

Column =
VAR _PreviousDay =
    MAXX (
        FILTER (
            MyTable,
            MyTable[Date]
                < EARLIER ( MyTable[Date] )
                && MyTable[Status] <> "OFF"
        ),
        MyTable[Date]
    )
VAR _result =
    SUMX (
        FILTER (
            MyTable,
            MyTable[Date]
                < EARLIER ( MyTable[Date] )
                && MyTable[Date] >= _PreviousDay
        ),
        MyTable[Cost]
    )
RETURN
    _result

Capture.JPG



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

@New_be , Two new columns like that.

 

Work Date = if(WEEKDAY([Date],2)>=6,BLANK(),[Date]) //OR
Work Date = if([Status]="OFF",BLANK(),[Date]) 
Last working date = maxx(filter('Date','Date'[Work Date]<EARLIER('Date'[Work Date])),'Date'[Work Date])

 

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
nandukrishnavs
Community Champion
Community Champion

@New_be 

 

DateDayStatus
19-05-2020Tuesday 
20-05-2020Wednesday 
21-05-2020Thursday 
22-05-2020Friday 
23-05-2020SaturdayOFF
24-05-2020SundayOFF
25-05-2020MondayOFF
26-05-2020TuesdayOFF
27-05-2020Wednesday 
28-05-2020Thursday 
29-05-2020Friday 
30-05-2020SaturdayOFF
31-05-2020SundayOFF
01-06-2020Monday 
02-06-2020Tuesday 
03-06-2020Wednesday 
04-06-2020Thursday 

 

Create a calculated column

 

Previous Working Day = MAXX(FILTER(MyTable,MyTable[Date]<EARLIER(MyTable[Date])&&MyTable[Status]<>"OFF"),MyTable[Date])

 

Capture.JPG



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂

 


Regards,
Nandu Krishna

Capture.new.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

A vey good solution! But what i mean is if the date is 1/6/2020 (monday), and we have 2 days off, we will take the data that add from date 29-31 May 2020. How to handle with it ?

@nandukrishnavs 
@amitchandak 

 

@New_be did you check my original post?


Regards,
Nandu Krishna

Capture.000.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

@nandukrishnavs i do check your solution and it is awesome! But i think i wrongly asked before. Pardon for that. My question is how can i get previous data like in this image that i draw. For example, if the date 27/5/2020 (wednesday) and we have 4 days off from 23-26 May 2020, then i want to take the data from before the last date off that is from 22-26 May 2020. And then the value for 27/5/2020 (wed) will b e the sum of cost from22-26 May 2020.


I dont know whether it is possible to do that in power bi, but i hope with your help, i can learn something new 🤗

@New_be 

 

Try this

Column =
VAR _PreviousDay =
    MAXX (
        FILTER (
            MyTable,
            MyTable[Date]
                < EARLIER ( MyTable[Date] )
                && MyTable[Status] <> "OFF"
        ),
        MyTable[Date]
    )
VAR _result =
    SUMX (
        FILTER (
            MyTable,
            MyTable[Date]
                < EARLIER ( MyTable[Date] )
                && MyTable[Date] >= _PreviousDay
        ),
        MyTable[Cost]
    )
RETURN
    _result

Capture.JPG



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

can i change my(cost) column in your code into a measure? i mean, can i use measure instead of column? 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.