My goal is to look at they year and see how many cars were in a shop each month. That is why I need the nested iif. A car can go in shop and be there several months and may not have an out date. That is why I don't think that the above query would work because I need to catch all the scenarios.
1. It went in shop and out of shop in the same month
2. It went in shop but is still in shop that month
3. It went in shop in a previous month and is still in shop
4. It went in shop in a previous month and out this month
5. It went in shop this month or a previous month and still does not have a shop out date.
So far it looks like my nested iif catches all the scenarios, even though it is a bit yuck.
Even more crazy, I almost have the IIF working for the count as well with this.
Code:
JanuaryDays: IIf([ShopArrival]=[ShopOut],1,IIf([ShopArrival]>#1/31/2022#,0,IIf([ShopArrival]>=#1/1/2022# And [ShopOut]<=#1/31/2022#,[ShopArrival]-[ShopOut],IIf([ShopArrival] Between #1/1/2022# And #1/31/2022# And [ShopOut]>#1/31/2022# Or [ShopOut] Is Null,#1/31/2022#-[ShopArrival],IIf([ShopArrival]<#1/1/2022# And [ShopOut]>#1/31/2022# Or [ShopOut] Is Null,31,IIf([ShopArrival]<#1/1/2022# And [ShopOut] Between #1/1/2022# And #1/31/2022#,#1/1/2022#-[ShopOut],0))))))
Still tweaking a bit because one of them is giving me a negative number so i have to switch the order somewhere.