Need to transform columns-lists into a coincidence matrix (array)

AusterRulez

New Member
Joined
Jan 17, 2025
Messages
3
Office Version
  1. 365
Platform
  1. MacOS
I have a table, in Excel, with three columns 1)list of individuals, 2)different time points and 3) their locations, which I need to transform into an array (coincidence matrix) by scoring the number of times two individual are simultaneously at the same place. The Table has more than 13,000 rows. have tried CONCATENATION OF Time&Place and used a Pivot Table but I could not figure out the way to generate the array. The main diagonal should be the number of occurrences of each individual. Unfortunately, I have not experience with Power Query.
Matrix.jpg
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
@Palo it would be helpful if you explained how. Especially as the OP has said they don't know how to do it with a pivot table.
 
Upvote 0
This gives most of the correct count except one cell - potentially a typo on your end (in red). Not sure how it'll perform on larger data set.
Book1
ABCDEFGHI
1Ind.TimePlaceI1I2I3I4
2I111:00AI13
3I211:00AI211
4I312:00AI3102
5I412:00AI41022
6I111:00B
7I113:00C
8I313:00C
9I413:00C
Sheet3
Cell Formulas
RangeFormula
F1:I1F1=TOROW(E2#)
E2:E5E2=UNIQUE(A2:A9)
F2:I5F2=LET( a,A2:A9,u,UNIQUE(a),t,B2:B9&C2:C9,rw,ROWS(u), MAKEARRAY(rw,rw,LAMBDA(r,c,IF(r>=c,SUM(MAP(UNIQUE(t),LAMBDA(m,LET(f,FILTER(a,t=m),INT(SUM((INDEX(u,r)=f)+(INDEX(u,c)=f))/2))))),""))) )
Dynamic array formulas.
 
Upvote 0
Solution
Cubist formula does not work with the originial dataset due to memory bottleneck (I'm currently using24GB RAM on a macbookpro M2). Any ideas? Thanks in advance.
 
Upvote 0
It's actually not too hard to do in Power Query just using the UI.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="your_data"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Time", type time}, {"Individual", type text}, {"Place", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"Time", "Place"}, #"Changed Type", {"Time", "Place"}, "Changed Type", JoinKind.LeftOuter),
    #"Expanded Changed Type" = Table.ExpandTableColumn(#"Merged Queries", "Changed Type", {"Individual"}, {"Individual.1"}),
    #"Grouped Rows" = Table.Group(#"Expanded Changed Type", {"Individual", "Individual.1"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Pivoted Column" = Table.Pivot(#"Grouped Rows", List.Distinct(#"Grouped Rows"[Individual.1]), "Individual.1", "Count", List.Sum)
in
    #"Pivoted Column"
 
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 0
Cubist formula does not work with the originial dataset due to memory bottleneck (I'm currently using24GB RAM on a macbookpro M2). Any ideas? Thanks in advance.
Formulas have their limitations a your ask is quite niche and the native functions are't built to do something like that thus it's very inefficient. Your best bet is to use VBA or PowerQuery.
 
Upvote 0

Forum statistics

Threads
1,225,741
Messages
6,186,763
Members
453,370
Latest member
juliewar

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