最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

VBA or Excel? Lookup reference from one column into and return least occurring value from another - Stack Overflow

programmeradmin2浏览0评论
ID Name Status
1234 ABC In Progress
1234 ABC Completed
1234 ABC Not Started
1234 ABC Not Started
2345 DEF In Progress
2345 DEF Completed
2345 DEF Completed
2345 DEF Not started
ID Name Status
1234 ABC In Progress
1234 ABC Completed
1234 ABC Not Started
1234 ABC Not Started
2345 DEF In Progress
2345 DEF Completed
2345 DEF Completed
2345 DEF Not started

Hi All,

I have a scenario where I need to show an overall status for each item (e.g. ID or Name). So the results in column D would show "Not started" for ID1234 as it is the most commonly occurring status and should be logically correct.

However, for ID2345 the logical result should still show "Not Started" as there is one "Not started" across the whole item status.

There is a priority here Not started > In Progress > Completed.

I have tried using the following formula to scan a column and get the least occuring value but dont think it would work logically. Is this something that would be solved with Excel formulas, or do I need to use VBA here?

=INDEX(D2:D8,MATCH(MIN(IF(COUNTIF(D2:D8,D2:D8)=0,"",COUNTIF(D2:D8,D2:D8))),COUNTIF(D2:D8,D2:D8),0))

Share Improve this question edited yesterday P.b 11.5k2 gold badges15 silver badges32 bronze badges asked yesterday SAP2022SAP2022 11 bronze badge New contributor SAP2022 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

2 Answers 2

Reset to default 0
=LET(s,{"Not started","In Progress","Completed"},INDEX(s,MODE.SNGL(SORT(IFERROR(XMATCH([Status],s)/([ID]=[@ID]),"")))))

If I understand it correctly you're not looking for the status that has the highest frequency per ID, but return status Not Started if found, else return In Progress if found, else return Completed (if found).

Using M365 you could use:

=@TOCOL(IFS((B$2:B$7=B2)*(D$2:D$7={"Not started","In Progress","Completed"}),D$2:D$7),2,1)

Or:

=LET(i,B$2:B$7,s,D$2:D$7,L,LAMBDA(x,y,FILTER(s,(i=@i)*(LEFT(s)=x),y)),@L("N",L("I",L("C","")))) (Use in same row as ID you're checking)

Or using older Excel you could use: =INDEX({"Not Started","In Progress","Completed"},MATCH(1,MMULT(TRANSPOSE(N(B$2:B$7=B2)),N(D$2:D$7={"Not Started","In Progress","Completed"})),0))

Not sure the above requires being entered with ctrl+shift+enter

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论