多个单元嵌套IF公式Excel

时间:2016-12-09 21:33:56

标签: excel

我正在尝试从两个不同的单元格中在Excel中编写公式。这就是我所拥有的:

=IF(C5="US",IF(I5="C","1,000",IF(I5="V","2,500",IF(I5="F","2,500",IF(C5="NIFA",IF(I5="C","1,000",IF(I5="V","2,500",IF(I5="F","2,500",IF(C5="West",IF(I5="C","1,000",IF(I5="V","2,000",IF(I5="F","2,000"))))))))))))

以下是我目前的情况:

{{1}}

我对这个公式的问题是,C5中的任何东西都不是美国的“FALSE” - 所有美国都没事。

提前致谢!

2 个答案:

答案 0 :(得分:1)

此方法将数据与查找逻辑分开,因此可扩展。这有点类似于Scott Craner的第一个建议(在评论中),但基于2D查找。

如果您按照以下方式排列数据,则可以使用此公式获得答案:

=VLOOKUP($B$6,$A$2:$D$4,MATCH($B$7,$B$1:$D$1,0)+1,0)

请注意,MATCH(...)+1偏移包含第一组查找值的第一列。 E.g:

enter image description here

其中给出了2500的正确结果:

enter image description here

答案 1 :(得分:0)

这将涵盖所有九种情况:

<script type="text/javascript">
    $(document).ready(function () {
        $.ajax({
            type: "POST",
            contentType: "application/json",
            data: "{}",
            url: "Default.aspx/GetEvents",
            dataType: "json",
            success: function (data) {
                $('div[id*=fullcal]').fullCalendar({
                    header: {
                        left: 'prev,next today',
                        center: 'title',
                        // right: 'timelineDay,agendaTwoDay,timelineThreeDays,month,agendaWeek,agendaDay,listWeek'//New1-agendaTwoDay
                        right: 'timelineDay,timelineThreeDays,agendaWeek,month,listWeek'
                    },
                    aspectRatio: 1.8,//New4
                    scrollTime: '00:00', //New5 undo default 6am scrollTime
                    // defaultView: 'agendaDay',//New2
                    defaultView: 'timelineDay',//New2
                    views: {//New3
                        timelineThreeDays: {
                            type: 'timeline',
                            duration: { days: 3 }
                        }
                    },

                    //views: {//New3
                    //    agendaTwoDay: {
                    //        type: 'agenda',
                    //        duration: { days: 2 },

                            // views that are more than a day will NOT do this behavior by default
                            // so, we need to explicitly enable it
                    //        groupByResource: true

                    //        //// uncomment this line to group by day FIRST with resources underneath
                    //        //groupByDateAndResource: true
                    //    }
                    //},

                    //// uncomment this line to hide the all-day slot
                    //allDaySlot: false,
                    schedulerLicenseKey: 'CC-Attribution-NonCommercial-NoDerivatives',//New for Licence
                    eventLimit: true, // allow "more" link when too many events
                    editable: true,
                    //new Resourses
                    resourceLabelText: 'Rooms',
                    resources: [
                        { id: 'a', title: 'Auditorium A' },
                        { id: 'b', title: 'Auditorium B', eventColor: 'green' },
                        { id: 'c', title: 'Auditorium C', eventColor: 'orange' },

                    ],
                    //Resourses
                    events: $.map(data.d, function (item, i) {
                        var event = new Object();
                        event.id = item.EventID;
                        event.start = new Date(item.StartDate);
                        event.end = new Date(item.EndDate);
                        event.title = item.EventName;
                        event.url = item.Url;
                        event.ImageType = item.ImageType;
                        //new 
                        event.resourceId = item.resourceId;
                        return event;
                    }), eventRender: function (event, eventElement) {
                        if (event.ImageType) {
                            if (eventElement.find('span.fc-event-time').length) {
                                eventElement.find('span.fc-event-time').before($(GetImage(event.ImageType)));
                            } else {
                                eventElement.find('span.fc-event-title').before($(GetImage(event.ImageType)));
                            }
                        }
                    },
                    loading: function (bool) {
                        if (bool) $('#loading').show();
                        else $('#loading').hide();
                    }
                });
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                debugger;
            }
        });
        $('#loading').hide();
        $('div[id*=fullcal]').show();
    });
    function GetImage(type) {
        if (type == 0) {
            return "<br/><img src = 'Styles/Images/attendance.png' style='width:24px;height:24px'/><br/>"
        }
        else if (type == 1) {
            return "<br/><img src = 'Styles/Images/not_available.png' style='width:24px;height:24px'/><br/>"
        }
        else
            return "<br/><img src = 'Styles/Images/not_available.png' style='width:24px;height:24px'/><br/>"
    }

</script>

(并且不需要一个 IF