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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Previous Day for Shift Timeframes Saturday=Friday

Hi guys,

 

i need help with a function where i calculate a measure for production.

 

ScrapPercentage Yesterday = 

DIVIDE(CALCULATE(SUM(TicketTable[ScrapQuantity]),PREVIOUSDAY(TicketTable[ShiftDate])),CALCULATE(SUM(OEE_1[Menge]),PREVIOUSDAY(OEE_1[SchichtDatum]),OEE_1[Art]="R"),0)+0
 
The problem is that the previousdayfunction doesnt work because the shiftdate (its an SQL Table) over the weekend will be counted to friday. How can i correctly calculate the value then? Because i need to skip 1 day.
 
For example today 7.2. i need the "previousday" value of the the 4.2
Thats the problem for mondays..
 
 
Appreciate your help!
BR
Fabian
 
 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , You can create rank on working days

new columns in date table

Work Day = if(WEEKDAY([Date],2)>=6,0,1)
Work Date = if(WEEKDAY([Date],2)>=6,BLANK(),[Date])
Work Date Cont = if([Work Day]=0,maxx(FILTER('Date',[Date]<EARLIER([Date]) && [Work Day]<> EARLIER([Work Day]) ),[Date]),[Date])
Work Date cont Rank = RANKX(ALL('Date'),[Work Date],,ASC,Dense)

 

 

measures

This Day = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Work Date cont Rank]=max('Date'[Work Date cont Rank])))
Last work day = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Work Date cont Rank]=max('Date'[Work Date cont Rank])-1))

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

What does the rank function do in this case? i try to understand everything. And why you using for this day not just the formula today() ? 

amitchandak
Super User
Super User

@Anonymous , You can create rank on working days

new columns in date table

Work Day = if(WEEKDAY([Date],2)>=6,0,1)
Work Date = if(WEEKDAY([Date],2)>=6,BLANK(),[Date])
Work Date Cont = if([Work Day]=0,maxx(FILTER('Date',[Date]<EARLIER([Date]) && [Work Day]<> EARLIER([Work Day]) ),[Date]),[Date])
Work Date cont Rank = RANKX(ALL('Date'),[Work Date],,ASC,Dense)

 

 

measures

This Day = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Work Date cont Rank]=max('Date'[Work Date cont Rank])))
Last work day = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Work Date cont Rank]=max('Date'[Work Date cont Rank])-1))

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.