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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Kavyachaganti
Regular Visitor

Find last business day of month in power query

Hi All,

Requirement1: 

Source team is generating price files on daily basis to the shared path. My requirement is to get only last business day of each month file in to Power Query & other files to be excluded. If last working of month is holiday then before day file to be selected.

Below highlighted file only to be selected for month of March.

Kavyachaganti_0-1682681398284.png

In below example last working day is holiday so prior date file to be selected.

Kavyachaganti_1-1682681578289.png

Requirement2:

Also prices of current month should fetch from previous month file. Each file is storing data of forward prices.

 

Some one of you please help me with this requirement in Power Query.

 

Thanks in Advance.

 

1 ACCEPTED SOLUTION
ThxAlot
Super User
Super User

Last Workday.xlsx

Last Workday.pbix

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLXNzDSNzIwMlbSUYpUitUBCllgCBnqGxijKcIUscAUssQQMjbAFEI23Q9mnwmGfWgixqgisQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Workday = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Workday", type text}}),
    #"Last Workday of Last Month" = let rs = Table.ToRecords(#"Changed Type") in Table.AddColumn(#"Changed Type", "LWLM", (r) => List.Last(List.Select(rs, each Date.EndOfMonth([Date])=Date.StartOfMonth(r[Date])-#duration(1,0,0,0) and [Workday]="Y"))[Date]?)
in
    #"Last Workday of Last Month"

 

 

 

ThxAlot_0-1682687152939.png

 

ThxAlot_3-1682688933234.png

 

 

A showcase of powerful Excel worksheet formulas,

 

 

 

=IFERROR(MAX(FILTER([Date];(EOMONTH([Date]+0;0)=EOMONTH([@Date];-1))*([Workday]="Y")));"")

 

 

 

ThxAlot_2-1682688163295.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



View solution in original post

2 REPLIES 2
ThxAlot
Super User
Super User

Last Workday.xlsx

Last Workday.pbix

 

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjLXNzDSNzIwMlbSUYpUitUBCllgCBnqGxijKcIUscAUssQQMjbAFEI23Q9mnwmGfWgixqgisQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Workday = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Workday", type text}}),
    #"Last Workday of Last Month" = let rs = Table.ToRecords(#"Changed Type") in Table.AddColumn(#"Changed Type", "LWLM", (r) => List.Last(List.Select(rs, each Date.EndOfMonth([Date])=Date.StartOfMonth(r[Date])-#duration(1,0,0,0) and [Workday]="Y"))[Date]?)
in
    #"Last Workday of Last Month"

 

 

 

ThxAlot_0-1682687152939.png

 

ThxAlot_3-1682688933234.png

 

 

A showcase of powerful Excel worksheet formulas,

 

 

 

=IFERROR(MAX(FILTER([Date];(EOMONTH([Date]+0;0)=EOMONTH([@Date];-1))*([Workday]="Y")));"")

 

 

 

ThxAlot_2-1682688163295.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LeanAndPractise(Everyday)


)



Mahesh0016
Solution Sage
Solution Sage

@Kavyachaganti please Try to this Date.EndOfMonth([Datemodify]) in using custom column.


@Kavyachaganti If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors