cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Post Patron

## Filter - Previous working day

i have this code to identify "today". is there a method i could use to also identify previous working day, ihave a coloumn that indicates if its a working day or not and returns 1,0

WorkingDay = if(WEEKDAY([Date],2) >=6,0,1)

Is Today =
var _max = maxx(filter('Date', 'Date'[Date] <=today() && [WorkingDay] =1),'Date'[Date])
return
Switch(True(),
[Date] = _max, "Today",
Format([Date], "DD/MM/YYYY"))

1 ACCEPTED SOLUTION
Resident Rockstar

So you are doing 2 Calculated columns? your "today" is not actually today, but working day...you want something like this?

``````test =
var workingDays = filter('Date', 'Date'[Date] <=today() && [WorkingDay] =1)
var today = MAXX(workingDays,[Date])
var previous = MAXX(FILTER(workingDays,[Date]<today),[Date])
return
SWITCH(TRUE(),
[Date]=today,"Today",
[Date] = previous, "Previous Working Day",
Format([Date], "DD/MM/YYYY"))``````

5 REPLIES 5
Post Patron

Resident Rockstar

So you are doing 2 Calculated columns? your "today" is not actually today, but working day...you want something like this?

``````test =
var workingDays = filter('Date', 'Date'[Date] <=today() && [WorkingDay] =1)
var today = MAXX(workingDays,[Date])
var previous = MAXX(FILTER(workingDays,[Date]<today),[Date])
return
SWITCH(TRUE(),
[Date]=today,"Today",
[Date] = previous, "Previous Working Day",
Format([Date], "DD/MM/YYYY"))``````

New Member

I would like to calculate two/three/four previous working days, how do I do ?

Resident Rockstar

Try it

``````test =
var workingDays = filter('Date', 'Date'[Date] <=today() && [WorkingDay] =1)
var today = MAXX(workingDays,[Date])
var previous = MAXX(FILTER(workingDays,[Date]<today),[Date])
var pre2day = MAXX(FILTER(workingDays,[Date]< previous),[Date])
return
SWITCH(TRUE(),
[Date]=today,"Today",
[Date] = previous, "Previous Working Day",
[Date] = pre2day, "Previous 2 Working Day",
Format([Date], "DD/MM/YYYY"))``````

Super User

Last working  = maxx(filter('Date', 'Date'[Date] <today() && [WorkingDay] =1),'Date'[Date])

Also refer my blog

Traveling Across Workdays - What is next/previous Working day
https://community.powerbi.com/t5/Community-Blog/Travelling-Across-Workdays-Decoding-Date-and-Calenda...

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.