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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
ghaines
Resolver I
Resolver I

Need help determining last workday before a particular day in Power Query

I'm working to complete a date table where there is a "IsWorkday" column that is false for weekends and holidays.  I'm trying to find the workday that a sale should be counted for (They are counted for the previous day i.e. On Monday, the sales report for Friday is generated that includes weekend online sales)

 

I am trying to generate a list from the workdays previous to the current date, but running into issues.  Here is my attempt:

 

 

= Table.AddColumn(#"Renamed Columns", "CountedOn",  let _ = [AccDate] in each 
    List.Max(
        Table.Column(
            Table.SelectRows(
                #"Renamed Columns", each [IsWorkday] = true and [AccDate] <= _
            )
            , "AccDate"
        )
    )
)

 

 

Expression.Error: We cannot apply operator < to types Record and Date.
Details:
Operator=<
Left=
AccDate=1/07/2021
IsWorkday=TRUE
Month=Jul 2021
MonthKey=202201
Right=1/07/2021

 

If I modify 
[AccDate] <= _
to 
[AccDate] <= _[AccDate]
then it returns the latest date in my entire date table on every row.   Something seems to be wrong with my let expression?  But I can't work it out.

1 REPLY 1
ghaines
Resolver I
Resolver I

I have found a solution by not applying the date restriction or finding the max, instead returning the list of all workdays, and then adding a column using:

 

= Table.AddColumn(Custom2, "PreviousWorkday", each let __ = [AccDate] in List.Max(List.Select([List], each _ <= __)))

 

I'm not especially happy with it, so please help me with the question if possible.

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.