create column of unique values in date range possibly vstack

foranpower

New Member
Joined
Nov 4, 2019
Messages
8
Office Version
  1. 2021
Platform
  1. Windows
based on this thread, vstack seems to be able to create a column of unique values in a date range:

The goal is highest total value and the champion of the person with the highest sum in the date range. So whoever knocks down the most pins during the competition.
name
datepinsstart dateend datestacked unique namestotal pins
fred
3/28/2024​
73/1/20243/29/2024wilma (if possible first named based on having the most bowling pins knocked down)9 = (5+4)
wilma
3/15/2024​
5fred7
wilma
3/7/2024​
4
dino
2/28/2024​
3

Here Wilma would win because during March she had the most pins kocked down, and dino would not show up because he did not bowl during the month.

Tried this formula based on the other post, but get a #name error.
=TOCOL(IF((B2:B5>=E2)*(B2:B5<=F2)*(A2:A5<>""),A2:A5,1/0),3,1)
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
PQ Refresh.xlsm
ABCDEFGHI
1MonthJanuary
2NamedatepinsMarchFebruary
3fred3/28/20247March
4wilma3/15/20245April
5wilma3/17/20244May
6dino2/28/20243June
7July
8August
9NameTotal PinsSeptember
10wilma9October
11fred7November
12December
Sheet1
Cells with Data Validation
CellAllowCriteria
E2List=$H$1:$H$12


Load your data as Table1 to Power Query Editor

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"pins", Int64.Type}, {"date", type date}}),
    #"Extracted Month Name" = Table.TransformColumns(#"Changed Type", {{"date", each Date.MonthName(_), type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Extracted Month Name", each ([date] = Table2)),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Name"}, {{"Total Pins", each List.Sum([pins]), type nullable number}}),
    #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Total Pins", Order.Descending}})
in
    #"Sorted Rows"

Load a parameter query to the PQE. This is the month lookup using Data Validation

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    Month = Source{0}[Month]
in
    Month

You can then refresh the results with each month change by creating a command button with the following VBA

VBA Code:
Private Sub CommandButton1_Click()
ActiveWorkbook.RefreshAll
End Sub
 
Upvote 1
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 1
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
I failed to save that before. Thanks for the tip. Fluff, it was your solution to a previous problem that got me thinking this may actually be possible.
 
Upvote 0
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
2021
 
Upvote 0
Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

- Follow this link to learn how to install Power Query in Excel 2010 / 2013.

- Follow this link for an introduction to Power Query functionality.

- Follow this link for a video which demonstrates how to use Power Query code provided.
 
Upvote 1
PQ Refresh.xlsm
ABCDEFGHI
1MonthJanuary
2NamedatepinsMarchFebruary
3fred3/28/20247March
4wilma3/15/20245April
5wilma3/17/20244May
6dino2/28/20243June
7July
8August
9NameTotal PinsSeptember
10wilma9October
11fred7November
12December
Sheet1
Cells with Data Validation
CellAllowCriteria
E2List=$H$1:$H$12


Load your data as Table1 to Power Query Editor

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"pins", Int64.Type}, {"date", type date}}),
    #"Extracted Month Name" = Table.TransformColumns(#"Changed Type", {{"date", each Date.MonthName(_), type text}}),
    #"Filtered Rows" = Table.SelectRows(#"Extracted Month Name", each ([date] = Table2)),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Name"}, {{"Total Pins", each List.Sum([pins]), type nullable number}}),
    #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Total Pins", Order.Descending}})
in
    #"Sorted Rows"

Load a parameter query to the PQE. This is the month lookup using Data Validation

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    Month = Source{0}[Month]
in
    Month

You can then refresh the results with each month change by creating a command button with the following VBA

VBA Code:
Private Sub CommandButton1_Click()
ActiveWorkbook.RefreshAll
End Sub
That is quite impressive code.
Still trying to figure it all out.

I copied your table, then
-> data
--> from table/range
--->view
---->advanced editor
-----> copy pasted your code
got it working up until table2. when i try to highlight two parts it says can't select multiple areas.

if possible, could it be for a date range between two dates say 1 March - 27 April a variable range.
Not sure if useful thinking: vstack(sum of pins as you put it, by name, filter (between starting on start date to ending on end date)

Just learning about power query looking up videos of how to do it and learning from you. Your patience is appreciated
 
Upvote 0
With a formula
Fluff.xlsm
ABCDEFGHI
1NamedatepinsStart dateEnd dateNameTotal
2fred28/03/2024701/03/202429/03/2024wilma9
3wilma15/03/20245fred7
4wilma17/03/20244
5dino28/02/20243
6
Data
Cell Formulas
RangeFormula
H2:I3H2=LET(u,UNIQUE(FILTER(A2:A100,(B2:B100>=E2)*(B2:B100<=F2))),SORT(CHOOSE({1,2},u,SUMIFS(C:C,B:B,">="&E2,B:B,"<="&F2,A:A,u)),2,-1))
Dynamic array formulas.
 
Upvote 1
Solution
Here is how I formulated the Mcode to allow for a range of dates.
Build two tables. Start and End. Bring them into the PQ Editor as before and Close and Load to a connection only.

Here is the new Mcode which incorporate those two tables referred to as Table5 and Table6 in the example.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"pins", Int64.Type}, {"date", type date}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each [date] >= Table5 and [date] <= Table6),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"Name"}, {{"Total Pins", each List.Sum([pins]), type nullable number}}),
    #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Name", Order.Ascending}})
in
    #"Sorted Rows"
Here is a new link with both examples.
 
Upvote 1

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top