excel-formulavlookupcountif

Dynamically averaging data Per ID Per Time period


I have the following Table below (more detailed in the Image):

Sample Data

Sample Data

Name Date ID Question 1 Question 2 Question 3
Brian Aga 3/7/2024 332235 NA NA No
Brian Aga 3/8/2024 450086 NA NA No
Brian Aga 3/14/2024 268563 No Yes NA
Gwen Jolly 3/15/2024 227115 Yes Yes Yes
Gwen Jolly 3/19/2024 866189 NA NA NA
Gwen Jolly 3/20/2024 655908 NA NA NA
Helen Abella 3/14/2024 436578 No Yes NA
Helen Abella 3/8/2024 209037 NA NA NA
Brian Aga 3/14/2024 313267 No Yes NA
Brian Aga 4/19/2024 268552 No Yes NA
Brian Aga 4/29/2024 763410 No Yes NA
Gwen Jolly 4/17/2024 566422 NA NA Yes
Gwen Jolly 4/17/2024 776709 NA NA NA
Gwen Jolly 4/16/2024 750650 NA Yes NA
Helen Abella 3/29/2024 764914 NA NA No

I am looking to be able to select a User and then have the subsequent Metrics for Average Last Month, Average the Month Before, and YTD Average populate. YTD Average cannot be the averages per month averaged out, it is the total data Average to date.

What I am actually measuring is the answers from Questions 1, 2, and 3 and the number of Yes answers against the total of Yes and No answers per month per User. It is being calculated with a =CountIF()/SUM(CountIFS()) statement.

Note: Sometimes months of data are skipped, so it would have to populate based on the last recorded months data and not the last calendar month. In the sample image the Orange highlighted area is where and how it would need to populate.

For a small data set like this for every group of names per month sections I was using: =COUNTIF(D2:F4,"Yes")/SUM(COUNTIFS(D2:F4,{"No","Yes"}))

...per row highlighted in Green in the Sample Data, but this requires me to write different formulas in different cells and refer back to different cells differently, it is not efficient along with monthly maintenance vs a drag and drop new data solution...furthermore if the data isn't grouped properly it causes more problems and inaccuracies


Solution

  • Here is the following formula, which one could use to resolve:

    enter image description here


    =LET(
         _CriteriaOne, (TEXT(EOMONTH(TODAY(),{-1,-2}),"e-m")=TEXT(B2:B16,"e-m")),
         _CriteriaTwo, (I2=A2:A16),
         _Questions, D2:F16,
         _LastMonth, FILTER(_Questions, TAKE(_CriteriaOne,,1)*_CriteriaTwo,""),
         _MonthBefore, FILTER(_Questions, TAKE(_CriteriaOne,,-1)*_CriteriaTwo,""),
         _YTD, FILTER(_Questions, _CriteriaTwo,""),
         VSTACK(IFERROR(SUM(N(_LastMonth="Yes"))/SUM(N(_LastMonth<>"NA")),0),
         IFERROR(SUM(N(_MonthBefore="Yes"))/SUM(N(_MonthBefore<>"NA")),0),
         IFERROR(SUM(N(_YTD="Yes"))/SUM(N(_YTD<>"NA")),0)))