SOLVED

Conditional Lookup Based on Two Different Tables to Produce Pivot

%3CLINGO-SUB%20id%3D%22lingo-sub-2712343%22%20slang%3D%22en-US%22%3EConditional%20Lookup%20Based%20on%20Two%20Different%20Tables%20to%20Produce%20Pivot%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2712343%22%20slang%3D%22en-US%22%3E%3CP%3EI%20need%20help%20making%20this%20pivot%3A%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screen%20Shot%202021-09-02%20at%205.25.51%20PM.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307641i93F44C133A65F7C0%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Screen%20Shot%202021-09-02%20at%205.25.51%20PM.png%22%20alt%3D%22Screen%20Shot%202021-09-02%20at%205.25.51%20PM.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EColumns%20E%3AG%20lookup%20the%20bottom%20master%20lookup%20(K6%3AN9).%20I%20then%20thought%20I%20would%20make%20a%20second%20transfer%20lookup%20(top%20one%20in%20K1%3AR4)%20to%20fill%20in%20columns%20H%3AI%20based%20on%20%3DIFERRORVLOOKUP(%5B%40Name%5D%2CLookup_Transfer%2C5%2C0)%2C%5B%40Original%20Sector%5D)%2C%20which%20works%20but%20then%20I%20needed%20it%20to%20be%20conditional%20of%20when%20it%20starts.%20I%20thought%20of%20a%20IF(AND%20where%20if%20the%20%5B%40Month%7D%20from%20the%20Data%20table%20is%20is%20less%20than%20or%20equal%20to%20(I%20thought%20this%20was%20easiest%20but%20gladly%20take%20whatever%20allows%20my%20end%20result)%20End%20in%20column%20R%20and%20less%20than%20or%20equal%20to%20YEAR%20of%20column%20R%20to%20%5B%40Year%5D%20in%20the%20Data%20table%20that%20way%20I%20get%20the%20correct%20values%20for%20columns%20H%3AI%20and%20then%20pivot%20to%20get%20the%20result%20I'm%20looking%20for.%20I%20get%20lost%20since%20how%20would%20I%20make%20it%20look%20to%20column%20R%20only%20for%20those%20who%20are%20in%20the%20transfer%20table.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Screen%20Shot%202021-09-02%20at%205.34.09%20PM.png%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F307643iA1CBFC77D444EDEB%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Screen%20Shot%202021-09-02%20at%205.34.09%20PM.png%22%20alt%3D%22Screen%20Shot%202021-09-02%20at%205.34.09%20PM.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAlso%2C%20is%20there%20a%20way%20to%20display%20a%20pivotable%20with%20only%20values%20looking%20forward%3F%20In%20my%20example%20I%20want%20years%202021%20and%202022%20to%20show%20months%205-12%20for%202021%20and%20month%201%20for%202022%20but%20without%20showing%20month%201%20in%202021.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20for%20any%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2712343%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-2715834%22%20slang%3D%22en-US%22%3ERe%3A%20Conditional%20Lookup%20Based%20on%20Two%20Different%20Tables%20to%20Produce%20Pivot%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2715834%22%20slang%3D%22en-US%22%3EThank%20you%20so%20much%20for%20the%20help.%20This%20really%20helped.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20have%20a%20few%20questions%20to%20understand%20this.%3CBR%20%2F%3E1)%20Why%20use%20the%20LOOKUP%20rather%20than%20another%20lookup%3F%20Even%20on%20MS%20support%20page%20on%20explaining%20the%20function%20tip%20says%20use%20a%20newer%20lookup.%3CBR%20%2F%3E2)%20How%20did%20you%20paste%20in%20the%20formula%20in%20those%20black%20boxes%20in%20your%20reply%3F%20It's%20really%20useful.%3CBR%20%2F%3E3)%20The%20same%20way%20you%20made%20the%20formula%20in%20the%20black%20boxes%2C%20how%20did%20you%20put%20it%20within%20those%20five%20lines%3B%20that%20is%2C%20how%20did%20you%20add%20the%20return%2Fnew%20line%20after%20the%201%2F%20in%20line%20one%20and%20continue%20in%20line%202%20and%20so%20on%3F%20I%20saw%20this%20was%20the%20same%20in%20Excel%20and%20makes%20the%20formula%20much%20easier%20to%20read.%20You%20also%20have%20spaces%20like%20in%20line%203%20with%20(_(%5B%40Year%5D....%20I%20used%20an%20underscore%20to%20show%20that%20space.%20How%20did%20you%20do%20this%20without%20Excel%20giving%20you%20an%20error%3F%3CBR%20%2F%3E4)%20the%201%2F%20in%20line%20one%2C%20what%20is%20it%20doing%3F%20The%20%2F%20or%20divide%20sign%3F%20It's%20used%20in%20lines%202%20and%203%20but%20they%20look%20to%20divide%20the%20wholes%20in%20parentheses%20but%20this%201%2F%20confuses%20me%20as%20to%20what%20it's%20doing.%3CBR%20%2F%3E%3CBR%20%2F%3EThank%20you%20so%20much%20for%20the%20help.%20I%20ask%20these%20questions%20so%20I%20can%20learn%20and%20improve%20my%20skills.%20Thank%20you%20again.%3C%2FLINGO-BODY%3E
Contributor

I need help making this pivot:

Screen Shot 2021-09-02 at 5.25.51 PM.png

 

Columns E:G lookup the bottom master lookup (K6:N9). I then thought I would make a second transfer lookup (top one in K1:R4) to fill in columns H:I based on =IFERRORVLOOKUP([@Name],Lookup_Transfer,5,0),[@Original Sector]), which works but then I needed it to be conditional of when it starts. I thought of a IF(AND where if the [@Month} from the Data table is is less than or equal to (I thought this was easiest but gladly take whatever allows my end result) End in column R and less than or equal to YEAR of column R to [@Year] in the Data table that way I get the correct values for columns H:I and then pivot to get the result I'm looking for. I get lost since how would I make it look to column R only for those who are in the transfer table.

Screen Shot 2021-09-02 at 5.34.09 PM.png

 

Also, is there a way to display a pivotable with only values looking forward? In my example I want years 2021 and 2022 to show months 5-12 for 2021 and month 1 for 2022 but without showing month 1 in 2021. 

 

Thank you for any help.

 

3 Replies
best response confirmed by Jpalaci1 (Contributor)
Solution

@Jpalaci1 

That's better to restructure data a bit and do everything with data mode, but it takes some time plus entire logic is unclear.

 

As variant you may use formulas for

(New) Sector

=IFNA( LOOKUP( 2, 1/
  ([@Name] & [@Company] &[@[Original Sector]] = Lookup_1st[Name] & Lookup_1st[Company] & Lookup_1st[Original Sector] ) /
  (  ([@Year]*100+[@Month]) >= (YEAR(Lookup_1st[Start])*100 + MONTH(Lookup_1st[Start]) ) ) /
  ( ([@Year]*100+[@Month]) <= ( YEAR(Lookup_1st[End])*100 + MONTH(Lookup_1st[End]) ) ),
  Lookup_1st[New Sector] ), "")

(New) Department

=IFNA( LOOKUP( 2, 1/
  ([@Name] & [@Company] &[@[Original Sector]] = Lookup_1st[Name] & Lookup_1st[Company] & Lookup_1st[Original Sector] ) /
  (  ([@Year]*100+[@Month]) >= (YEAR(Lookup_1st[Start])*100 + MONTH(Lookup_1st[Start]) ) ) /
  ( ([@Year]*100+[@Month]) <= ( YEAR(Lookup_1st[End])*100 + MONTH(Lookup_1st[End]) ) ),
  Lookup_1st[New Department] ), "")

 

 PivotTable doesn't show months without data, nothing special to do

image.png

Thank you so much for the help. This really helped.

I have a few questions to understand this.
1) Why use the LOOKUP rather than another lookup? Even on MS support page on explaining the function tip says use a newer lookup.
2) How did you paste in the formula in those black boxes in your reply? It's really useful.
3) The same way you made the formula in the black boxes, how did you put it within those five lines; that is, how did you add the return/new line after the 1/ in line one and continue in line 2 and so on? I saw this was the same in Excel and makes the formula much easier to read. You also have spaces like in line 3 with (_([@Year].... I used an underscore to show that space. How did you do this without Excel giving you an error?
4) the 1/ in line one, what is it doing? The / or divide sign? It's used in lines 2 and 3 but they look to divide the wholes in parentheses but this 1/ confuses me as to what it's doing.

Thank you so much for the help. I ask these questions so I can learn and improve my skills. Thank you again.

@Jpalaci1 , you are welcome.

1) On the one hand such pattern with LOOKUP() exists for about 30 years, that's actually for what this function was designed. On the other hand that's my personal preferences, I prefer LOOKUP(), INDEX/MATCH and XLOOKUP(), never used VLOOKUP() and HLOOKUP(). But that's up to you which one to use.

2) Replying on post find this "Insert code" icon in editor bar

image.png

click on it, select Excel Formula and paste the formula

image.png

 

3) That's just formatting. Expand formula bar, with long formula insert new line by Alt+Enter, use spaces to separate part of formulas. Space and new lines are ignored during formula evaluation.

In formula bar such formula looks like

image.png

Alternatively without such formatting

image.png

or

=IFNA(LOOKUP(2,1/([@Name]&[@Company]&[@[Original Sector]]=Lookup_1st[Name]& Lookup_1st[Company]&Lookup_1st[Original Sector])/(([@Year]*100+[@Month])>= (YEAR(Lookup_1st[Start])*100+MONTH(Lookup_1st[Start])))/(([@Year]*100+[@Month])<=( YEAR(Lookup_1st[End])*100+MONTH(Lookup_1st[End]))),Lookup_1st[New Sector]),"")

Much harder to read and maintain.

4) Yes, that's division. 1/(divider)