How to populate multiple columns based on different value in one column

时间:2016-02-12 21:46:49

标签: excel

I have an excel file as:

$(document).ready(function () {
    var triggered = parseInt(localStorage.getItem('triggered'));

    $("#link").click(function () {
        sessionStorage.reloadAfterPageLoad = true;
        window.location.reload();
    });

    $(function () {
        if (sessionStorage.reloadAfterPageLoad) {
            //Some code that I don't know to prevent executing the below code after page refresh if #link was clicked by user.
            alert("Link Clicked");
            sessionStorage.reloadAfterPageLoad = false;
        }
    });

    if (document.getElementById('divid').innerHTML.indexOf("Sampletext") != -1) {
        document.getElementById('inputid').value = 'example';
        if (!triggered) {
            localStorage.setItem('triggered', 1);
            $("#button").trigger('click');
        }
    }
});

I want to convert it in a report that informs me what all years did the person bought the product in the below format:

+----+------------+
| ID | Order date |
+----+------------+
| A  | 1/1/2011   |
| A  | 1/3/2012   |
| A  | 1/8/2013   |
| A  | 1/20/2014  |
| A  | 1/23/2015  |
| B  | 1/1/2011   |
| B  | 1/20/2014  |
| B  | 1/23/2015  |
+----+------------+

any help is much appreciated! Thanks!

1 个答案:

答案 0 :(得分:3)

Assuming the data is in column A and B, with a header row, and you have the years going across the top, you can use this (place in C2):

chrome.webRequest.onBeforeRequest.addListener( function (details) { var javascriptCode = loadSynchronously(details.url); // modify javascriptCode here return { redirectUrl: "data:text/javascript," + encodeURIComponent(javascriptCode) }; }, { urls: ["*://*.example.com/*.js"] }, ["blocking"]); and drag over and down.

enter image description here

Pretty straightforward. It takes the =IF(YEAR($B2)=C$1,"Yes","No") from column B, checks against the year in the current column's header row, and puts "Yes" if they match.

A note, we didn't do anything with the IDs. Perhaps that's okay, but I'm thinking you included them in your sample for some reason (maybe not though), so if you want to whittle this down further, update your OP.

edit: For funsies, in case you just want to drag willy-nilly, add a statement to leave it blank if there's no data in B: YEAR