Excel BI Challenge Workout 184

— CAN YOU SOLVE THIS - EXCEL CHALLENGE 184 —
(Solutions in any language are also welcome for Excel Challenges)

List the years in this century which are having at least 2 months which had 5 Fridays, 5 Saturdays and 5 Sundays.
For example, year 2010 had January and October which met this criterion.

Post answers in Comment.

(Your formula need not be a single formula. You can write multiple formulas to arrive at a solution. Also your formula need not be different from others as long as you have worked out your formula independently)

Download Practice File - https://lnkd.in/dfm2CPTB

#excel, #excelchallenge, #powerquerychallenge, #daxchallenge, #m, #dax, #powerbi, #powerquery, #powerpivot, #sheets, #googlesheets, #data, #analytics, #businessintelligence, #finance, #office365, #python, #r

Excel BI LinkedIn Post

LinkedIn Post by
Štěpán Rešl

My Power Query solution:

let
Source = [List.Select](http://list.select/)(
{2000..2099},
(y) =>
List.Count(
[List.Select](http://list.select/)(
{1..12},
(m) =>
let
innerSelection = List.Dates(
[#date](https://www.linkedin.com/feed/hashtag/?keywords=date)(y, m, 1), [Date.Day](http://date.day/)(Date.EndOfMonth([#date](https://www.linkedin.com/feed/hashtag/?keywords=date)(y, m, 1))), [#duration](https://www.linkedin.com/feed/hashtag/?keywords=duration)(1, 0, 0, 0)
),
fct = (vl as number) =>
if List.Count([List.Select](http://list.select/)(innerSelection, each Date.DayOfWeek(_, 1) = vl)) >= 5 then
true
else
false
in
List.Count(
[List.Select](http://list.select/)(
List.Generate(
() => [vl = 6, res = fct(vl)],
each (_[vl] ?? 1) > 3,
each [vl = _[vl] - 1, res = fct(vl)],
each [res]
),
each _
)
) = 3
)
) > 1
)
in
Source

LinkedIn post by:
LEONARD OCHEA

=LET(y,SEQUENCE(100,,2000),FILTER(y,BYROW(WEEKDAY(DATE(y,1,SEQUENCE(,31))),LAMBDA(a,SUM((a=VSTACK(1,6,7))*1)))>=15))

The key is only in the month of January

Rick Rothstein , If it’s about cutting, let’s try this

=LET(n,SEQUENCE(100,,2000),FILTER(n,WEEKDAY(DATE(n,1,1))=6))

It seems that you only need to analyze if the firstL

LinkedIn post by:
Bo Rydobon

M-Code

let
Source = [List.Select](http://list.select/)({2000..2099},(y)=> List.Count([List.Select](http://list.select/)({1..12}, (m)=> let d= [#date](https://www.linkedin.com/feed/hashtag/?keywords=date)(y,m,1) in Date.DayOfWeek(d)=5 and [Date.Day](http://date.day/)(Date.EndOfMonth(d))=31))>1)
in
Source

LinkedIn post by:
Alejandro Simón

Adjunto mi query…

let
Source = {Number.From([#date](https://www.linkedin.com/feed/hashtag/?keywords=date)(2000,01,01))..Number.From([#date](https://www.linkedin.com/feed/hashtag/?keywords=date)(2099,12,31))},
Fechas = Table.FromList(Source, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
Calc = Table.AddColumn(Fechas, "Custom", each
[a = Date.From([Column1]),
b = Date.Year(a),
c = Date.Month(a),
d = Date.DayOfWeek(a)]),
Expand = Table.ExpandRecordColumn(Calc, "Custom", {"a", "b", "c", "d"}),
Group = [Table.Group](http://table.group/)(Expand, {"b", "d", "c"}, {{"Count", each Table.RowCount(_)}}),
Dias = Table.SelectRows(Group, each ([d] = 0 or [d] = 5 or [d] = 6) and [Count] = 5),
GroupMonth = Table.SelectRows([Table.Group](http://table.group/)(Dias, {"b", "c"}, {{"Count", each Table.RowCount(_)}}), each [Count] > 2),
GroupYears = [Table.Group](http://table.group/)(GroupMonth, {"b"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
Sol = Table.SelectRows(GroupYears, each ([Count] = 2))[b]
in
Sol

LinkedIn post by:
Rafael González B

Hi Everyone… Here’s My PQ Code:

let

LDates = Table.FromList({Number.From([#date](https://www.linkedin.com/feed/hashtag/?keywords=date)(2000,1,1))..Number.From([#date](https://www.linkedin.com/feed/hashtag/?keywords=date)(2099,12,31))}, Splitter.SplitByNothing(), {"Dates"}, null, ExtraValues.Error),
TypeDate = Table.TransformColumnTypes(LDates,{{"Dates", type date}}),
IYear = Table.AddColumn(TypeDate, "Año", each Date.Year([Dates]), Int64.Type),
IMonth = Table.AddColumn(IYear, "Mes", each Date.Month([Dates]), Int64.Type),
NDay = Table.AddColumn(IMonth, "Nombre del día", each Date.DayOfWeekName([Dates]), type text),
FMS = Table.SelectRows(NDay, each ([Nombre del día] = "domingo" or [Nombre del día] = "sábado" or [Nombre del día] = "viernes")),
FGroup = [Table.Group](http://table.group/)(FMS, {"Año", "Mes", "Nombre del día"}, {{"Recuento", each Table.RowCount(_), Int64.Type}}),
FGreater5 = Table.SelectRows(FGroup, each [Recuento] >= 5),
SumRC = [Table.Group](http://table.group/)(FGreater5, {"Año", "Mes"}, {{"Total Series", each List.Sum([Recuento]), type number}}),
Filter15 = Table.SelectRows(SumRC, each [Total Series] >= 15),
GBYears = [Table.Group](http://table.group/)(Filter15, {"Año"}, {{"Recuento", each Table.RowCount(_), Int64.Type}}),
GT2 = Table.SelectRows(GBYears, each [Recuento] >= 2),
Result = Table.RemoveColumns(GT2,{"Recuento"})
in
Result

LinkedIn post by:
Zoran Milokanović

Five Fri Sat Sun w/ #powerquery. #bitanbit #powerbi

let
Source = DateTime.LocalNow(),
AddCenturyDates = let t = Number.IntegerDivide(Date.Year(Source), 100) * 100 in {Number.From([#date](https://www.linkedin.com/feed/hashtag/?keywords=date)((t+1), 1, 1))..Number.From([#date](https://www.linkedin.com/feed/hashtag/?keywords=date)((t+100), 12, 31))},
ConvertToDate = List.Transform(AddCenturyDates, each Date.From(_)),
ConvertToTable = Table.FromList(ConvertToDate, Splitter.SplitByNothing(), {"Date"}),
FormatDate = Table.TransformColumnTypes(ConvertToTable,{{"Date", type date}}),
InsertedYear = Table.AddColumn(FormatDate, "Year", each Date.Year([Date]), Int64.Type),
InsertedMonth = Table.AddColumn(InsertedYear, "Month", each Date.Month([Date])),
InsertedDayOfWeek = Table.AddColumn(InsertedMonth, "DayOfWeek", each Date.DayOfWeekName([Date], "en-US")),
PivotedDayOfWeek = Table.Pivot(InsertedDayOfWeek, List.Distinct(InsertedDayOfWeek[DayOfWeek]), "DayOfWeek", "Date", List.Count),
Filtered5Days = Table.SelectRows(PivotedDayOfWeek, each ([Friday] = 5) and ([Saturday] = 5) and ([Sunday] = 5)),
GroupedYears = [Table.Group](http://table.group/)(Filtered5Days, {"Year"}, {{"Months", each Table.RowCount(_), Int64.Type}}),
FilteredYears = Table.SelectRows(GroupedYears, each ([Months] >= 2)),
Solution = FilteredYears[Year]
in
Solution

LinkedIn post by:
Guillermo Arroyo

Power Query

let
a = {2000..2099},
b = [List.Select](http://list.select/)(a, (y)=>
let
d = List.Transform({1..12}, (m)=>
let
i = [#date](https://www.linkedin.com/feed/hashtag/?keywords=date)(y, m, 1),
f = Date.EndOfMonth(i),
e = List.Generate(()=> i, each _<= f, each Date.AddDays(_, 1)),
g = List.Count([List.Select](http://list.select/)(List.Transform(e, each Date.DayOfWeek(_, Day.Monday)), each _ > 3))
in
g >= 15),
h = List.Count([List.Select](http://list.select/)(d, each _))
in
h >= 2)
in
b

LinkedIn Post by:
Quadri Olayinka Atharu

This seems quite long and not elegant but it works

=LET(y,SEQUENCE(100,,2000),FILTER(y,
MAP(y,LAMBDA(years,SUM(--(DROP(REDUCE(0,SEQUENCE(12),
LAMBDA(a,b,LET(alldays,SEQUENCE(DATE(years,12,31)-DATE(years,1,1)+1,,DATE(years,1,1)),
dbm,FILTER(alldays,MONTH(alldays)=b),VSTACK(a,COUNT(FILTER(dbm,ISNUMBER(XMATCH(WEEKDAY(dbm),{1,6,7})))))))),1)=15))>=2))))

LinkedIn post by:
محمد حلمي

=LET(
n,SEQUENCE(100,,2000),
FILTER(n,MAP(n,LAMBDA(c,LET(
r,DATE(c,1,SEQUENCE(365)),SUM(--(MAP({1,3,5,7,8,10,12},
LAMBDA(a,
WEEKDAY(TAKE(FILTER(r,MONTH(r)=a),1))))=6))>1)))))

LinkedIn post by:
Kris Jaganah

=LET(a,DATE(2000,1,0)+SEQUENCE(36525),b,FILTER(YEAR(a)+MONTH(a)/100,WEEKDAY(a,2)>4),c,UNIQUE(b),d,FILTER(ROUND(c,0),MAP(c,LAMBDA(x,SUM(--(b=x))))>14),e,UNIQUE(d),FILTER(e,MAP(e,LAMBDA(y,SUM(--(d=y))))>1))

LinkedIn Post by:
Guillermo Arroyo

=DROP(REDUCE("",SEQUENCE(100,,2000),LAMBDA(i,j,IF(REDUCE(0,SEQUENCE(12),LAMBDA(x,z,LET(f,DATE(j,z,1),IF(AND(TAKE(FREQUENCY(WEEKDAY(SEQUENCE(EOMONTH(f,0)-f+1,,f),2),SEQUENCE(6)),-3)>=5),x+1,x))))>=2,VSTACK(i,j),i))),1)

Other way

=LET(n,SEQUENCE(100,,2000),FILTER(n,MAP(n,LAMBDA(p,LET(f,DATE(p,SEQUENCE(12),1),SUM(--(NETWORKDAYS.INTL(f,EOMONTH(f,0),"1111000")/3>=5)))>=2))))

LinkedIn post by:
Luan Rodrigues

let
Fonte = [
a = List.Dates([hashtag#date](https://www.linkedin.com/feed/hashtag/date/)(2000, 01, 01), 36524 , [hashtag#duration](https://www.linkedin.com/feed/hashtag/duration/)(1, 0, 0, 0)),
b = List.Buffer(a)
][b],
tab = Table.FromList(Fonte, Splitter.SplitByNothing(), null, null),
ma = Table.AddColumn(tab, "mes_ano", each Date.ToText([Column1],"MMyyyy")),
dy = Table.AddColumn(ma, "dia_semana", each Date.DayOfWeek([Column1])),
f1 = Table.SelectRows(dy, each ([dia_semana] = 0 or [dia_semana] = 5 or [dia_semana] = 6))
[[mes_ano],[dia_semana]],
gp = [Table.Group](http://table.group/)(f1, {"mes_ano"}, {{"Contagem", each
[
a = _,
b = Table.RowCount(Table.SelectRows([Table.Group](http://table.group/)(a,{"dia_semana"},{{"Count", each Table.RowCount(_)}} ), each [Count] = 5))
][b]
}}),
f2 = Table.SelectRows(gp, each ([Contagem] = 3)),
a = Table.AddColumn(f2, "Ano", each Text.End([mes_ano],4)),
gp2 = [Table.Group](http://table.group/)(a, {"Ano"}, {{"Contagem", each Table.RowCount(_)}}),
res = Table.SelectRows(gp2, each ([Contagem] = 2))[[Ano]]
in
res

LinkedIn post by:
Pratik Sathe

In the first column, enter a list of dates in the format “YYYY-MM-DD” that correspond to the months you want to check. For example, you could enter the dates “2023-08-01”, “2023-09-01”, “2023-10-01”, and so on.
In the second column, enter the following formula:

=IF(AND(WEEKDAY(A2)=6,DAY(DATE(YEAR(A2),MONTH(A2)+1,0))-28>=0),TRUE,FALSE)

The formula will return either TRUE or FALSE depending on whether the corresponding month has 5 Fridays, 5 Saturdays, and 5 Sundays.

LinkedIn post by:
Brian Julius

My hashtag#powerquery solution.

let
StartDate = Number.From( [hashtag#date](https://www.linkedin.com/feed/hashtag/date/)(2000, 1, 1)),
EndDate = Number.From( [hashtag#date](https://www.linkedin.com/feed/hashtag/date/)(2099, 12, 31)),
Source = Table.TransformColumnTypes( Table.FromList({ StartDate..EndDate }, Splitter.SplitByNothing(), null, null, ExtraValues.Error), {"Column1", type date}),
Rename = Table.RenameColumns(Source,{{"Column1", "Dates"}}),
Year = Table.AddColumn(Rename, "Year", each Date.Year([Dates]), Int64.Type),
MonthName = Table.AddColumn(Year, "Month Name", each Date.MonthName([Dates]), type text),
DayName = Table.AddColumn(MonthName, "Day Name", each Date.DayOfWeekName([Dates]), type text),
Group1 = [Table.Group](http://table.group/)(DayName, {"Year", "Month Name", "Day Name"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
Filter1 = Table.SelectRows(Group1, each ([Day Name] = "Friday" or [Day Name] = "Saturday" or [Day Name] = "Sunday") and ([Count] = 5)),
Group2 = [Table.Group](http://table.group/)(Filter1, {"Year", "Month Name"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
Filter2 = Table.SelectRows(Group2, each ([Count] = 3)),
Group3 = [Table.Group](http://table.group/)(Filter2, {"Year"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
Filter3 = Table.SelectRows(Group3, each ([Count] = 2)),
Clean = Table.RemoveColumns(Filter3,{"Count"})
in
Clean

LinkedIn Post by
محمد حلمي

=LET(
n,SEQUENCE(100,,2000),
FILTER(n,MAP(n,LAMBDA(c,
SUM(--(WEEKDAY(DATE(c,{1,3,5,7,8,10,12},1))=6))>1))))

LinkedIn post by:
Oscar Mendez Roca Farell

hi everyone, my proposal solution:

=LET(_y, SEQUENCE(100, ,2000), FILTER(_y, MAP(_y, LAMBDA(a, SUM(--(REDUCE("", SEQUENCE( ,12), LAMBDA(i, x ,LET(_f, DATE(a, x, 1), VSTACK(i, MOD( SUM(--(WEEKDAY( SEQUENCE( DAY(EOMONTH(_f, 0)), ,_f), 3)>3)), 5)))))=0))))>1))

LinkedIn post by:
Rick Rothstein

=LET(r,SEQUENCE(100,,2000),d,DATE(r,SEQUENCE(,12),31),FILTER(r,BYROW((WEEKDAY(d)=1)*(MONTH(d)=MONTH(d-7)),LAMBDA(r,SUM(r)>1))))

LinkedIn post by:
Hussein SATOUR

Thank you Excel BI

=LET(a, ROW(2000:2099), FILTER(a, MAP(a, LAMBDA(x, SUM(MAP(ROW(1:12)&"/"&x, LAMBDA(y,LET(m, SEQUENCE(EOMONTH(y,0) - y+1)&"/"&y, w, WEEKDAY(m), COUNTA(FILTER(m, (w=6) + (w=7) + (w=1))) = 15)))*1)>1))))

Linkedin Post by:
John Jairo V.View John Jairo V.’s profile

Hi to all!

One option could be:
:white_check_mark:

=LET(y,ROW(2000:2099),FILTER(y,MAP(y,LAMBDA(x,LET(d,x&"-1-1",SUM(NETWORKDAYS.INTL(d,30+d,1111&{"011",101,110}))=15)))))

Blessings!