Quantcast
Channel: Power Query topics
Viewing all articles
Browse latest Browse all 31096

Need a more efficient way of getting last working day of the month

$
0
0

Hello,

 

I have a DAX code of getting last working day of the month that works and I'm trying to find a better way of writing the Power Query version of it. 

 

I am trying to create a company calendar table. I have a list non-weekend dates that are company and vacation days off. From this I created the following in Power query and DAX:

DateYearMonthYear MonthIsWorkingDay
2024-01-042024012024-01Y
2024-01-052024012024-01N
...............
2024-03-292024032024-03N

 

So for January it was a normal month so last working day would be Jan 31. In March we had a vacation so last working day was Mar 28 (29 is vacation, 30 and 31 is Sat and Sun)

 

For DAX I got the last working day of the month by using the following code:

 

Month End Date = VAR _Year = Calendar[Year] VAR _Month = Calendar[Month Number] RETURN FORMAT( MAXX( FILTER(Date, Calendar[Year] = _Year && Calendar[Month Number] = _Month && Calendar[Bantrelworkday] = "Y"), Calendar[Date] ), "dddddd")

 


I'm open to suggestions for making the above more efficient. For Power Query I used the following code:

 

Table.AddColumn(#"Previous Step", "EOM Date", each let currentYearMonth = Text.From(Date.Year([Date])) & "-" & Text.PadStart(Text.From(Date.Month([Date])),2,"0"), filteredTable = Table.SelectRows(#"Previous Step", each [Year Month] = currentYearMonth and [BantrelWorkday] = "Y"), maxDate = List.Max(filteredTable[Date]) in maxDate)

 

 

Now for the Power Query i get the same output, but it takes forever to load, so i'm thinking there's a much better way of doing this, but i'm not as familiar with Power Query


Viewing all articles
Browse latest Browse all 31096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>