Creating an Excel formula

%3CLINGO-SUB%20id%3D%22lingo-sub-3000468%22%20slang%3D%22en-US%22%3ECreating%20an%20Excel%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3000468%22%20slang%3D%22en-US%22%3E%3CP%3EThere%20are%202%20sheets%20with%20each%204%20columns.%3C%2FP%3E%3CP%3EType%3A%20Startsession%20or%20Presentation%3C%2FP%3E%3CP%3EMethod%3A%20Method%20A%2C%20B%20or%20C%3C%2FP%3E%3CP%3ENumber%3A%20Unique%20identification%20number%20which%20can%20occur%20multiple%20times%3C%2FP%3E%3CP%3ERegion%3A%20Region%20can%20occur%20multiple%20times.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOn%20a%20third%20sheet%20I%20have%20a%20table%20with%20the%20regions%20and%20I%20want%20to%20count%20how%20much%20Unique%20numbers%20had%20both%20a%20startsession%20and%20presentation%20for%20methodB.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EExample%2C%20if%20the%20screenshot%20is%20the%20source%20file.%20The%20new%20table%20must%20show%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENoord%20holland%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%201%3C%2FP%3E%3CP%3EOverijssel%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%201%3C%2FP%3E%3CP%3EGelderland%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%200%3C%2FP%3E%3CP%3ENoord%20brabant%26nbsp%3B%20%26nbsp%3B%20%26nbsp%3B%200%3C%2FP%3E%3CP%3E...%3C%2FP%3E%3CP%3E...%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3000468%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3000655%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20an%20Excel%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3000655%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1227288%22%20target%3D%22_blank%22%3E%40Pieter23%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eis%20this%20what%20you%20want.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3000910%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20an%20Excel%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3000910%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1228265%22%20target%3D%22_blank%22%3E%40arnel_puzon%3C%2FA%3E%20Not%20exactly.%20The%20result%20in%20sheet%203%20should%20only%20count%20if%20a%20unique%20number%20has%20had%20both%20a%20presentation%20AND%20a%20startsession.%20So%20in%20my%20example%20'Noord%20holland'%20and%20'Overijssel'%20should%20return%201%20and%20'Zuid%20holland'%20should%20return%200%2C%20since%20the%20uniqe%20number%20only%20had%20a%20'Presentation'.%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3000923%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20an%20Excel%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3000923%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1227288%22%20target%3D%22_blank%22%3E%40Pieter23%3C%2FA%3E%26nbsp%3BLet%20me%20start%20by%20thanking%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1228265%22%20target%3D%22_blank%22%3E%40arnel_puzon%3C%2FA%3E%26nbsp%3Bfor%20taking%20the%20time%20to%20create%20a%20workbook%20that%20replicates%20your%20data.%20It%20enabled%20me%20to%2C%20fairly%20easily%2C%20create%20the%20desired%20output%20with%20Power%20Query%20as%20you%20can%20see%20in%20the%20attached%20file.%20It%20may%20need%20to%20be%20optimized%20to%20fit%20your%20real%20life%20data%2C%20but%20it%20demonstrates%20what%20you%20can%20achieve%20without%20complex%20formulae.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screenshot%202021-11-24%20at%2011.39.20.png%22%20style%3D%22width%3A%20565px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F329125i99DB447D1D565AEE%2Fimage-dimensions%2F565x231%3Fv%3Dv2%22%20width%3D%22565%22%20height%3D%22231%22%20role%3D%22button%22%20title%3D%22Screenshot%202021-11-24%20at%2011.39.20.png%22%20alt%3D%22Screenshot%202021-11-24%20at%2011.39.20.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20are%20new%20to%20PQ%2C%20check%20out%20the%20link%20below.%20It's%20a%20good%20starting%20point%20to%20learn%20more%20about%20it.%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fexceloffthegrid.com%2Fpower-query-introduction%2F%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fexceloffthegrid.com%2Fpower-query-introduction%2F%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3001037%22%20slang%3D%22en-US%22%3ERe%3A%20Creating%20an%20Excel%20formula%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3001037%22%20slang%3D%22en-US%22%3EThank%20you%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E!!%20Makes%20life%20easier.%20Now%20I%20only%20have%20to%20learn%20how%20to%20use%20Power%20Query...%3C%2FLINGO-BODY%3E
Occasional Contributor

There are 2 sheets with each 4 columns.

Type: Startsession or Presentation

Method: Method A, B or C

Number: Unique identification number which can occur multiple times

Region: Region can occur multiple times.

 

On a third sheet I have a table with the regions and I want to count how much Unique numbers had both a startsession and presentation for methodB. 

 

Example, if the screenshot is the source file. The new table must show:

 

Noord holland      1

Overijssel              1

Gelderland            0

Noord brabant      0

...

...

6 Replies

@Pieter23 

 

is this what you want.

@arnel_puzon Not exactly. The result in sheet 3 should only count if a unique number has had both a presentation AND a startsession. So in my example 'Noord holland' and 'Overijssel' should return 1 and 'Zuid holland' should return 0, since the uniqe number only had a 'Presentation'.

@Pieter23 Let me start by thanking @arnel_puzon for taking the time to create a workbook that replicates your data. It enabled me to, fairly easily, create the desired output with Power Query as you can see in the attached file. It may need to be optimized to fit your real life data, but it demonstrates what you can achieve without complex formulae.

Screenshot 2021-11-24 at 11.39.20.png

 

If you are new to PQ, check out the link below. It's a good starting point to learn more about it.

https://exceloffthegrid.com/power-query-introduction/ 

Thank you @Riny_van_Eekelen!! Makes life easier. Now I only have to learn how to use Power Query...
@Riny_van_Eekelen watched couple of youtube tutorials but still did'nt find out how to get the result I need. Can you help out?

@Pieter23 

As variant

= LET(
  u,   SORT( UNIQUE( Table1[Region]) ),
  cnt, --( u = TRANSPOSE( Table1[Region] ) ),
  pr,  --( Table1[Method] = "methodB" ) * ( Table1[Type] = "Presentation" ),
  ss,  --( Table1[Method] = "methodB" ) * ( Table1[Type] = "StartSession" ),
  CHOOSE( {1,2},
     u,
     MMULT( cnt, pr ) * MMULT( cnt, ss) )
)

which gives

image.png