I have a BAQ with Subqueries. It basically totals up each invoice for Sales with no freight charges for a selected time period. I am trying to compare that with my customer list and for each customer that didn’t have an invoice for that time period, I want it to add a 0.00 to the Invoice Total Field so I can use it when I’m comparing sales from year to year. I have the Total Field that is a Decimal file. I have created a Calculated Field below:
If you want shorter syntax, and you just need to check for a null value to replace, I like to use the IsNull(): IsNull(invoiceTotals1.Calculated_TotalNoFrght, 0)
I find it’s quicker to understand when I’m troubleshooting.
Per MS:
Returns the same type as check_expression . If a literal NULL is provided as check_expression , returns the datatype of the replacement_value . If a literal NULL is provided as check_expression and no replacement_value is provided, returns an int .
Okay, one more for you. I am trying to calculate a % on the Sales Columns. For some customers both columns might be null. I have this formula so far but am still getting an error.
@ckrusen
Okay, I am getting a formula headache Sorry, I am still learning how to code in Epicor, let alone C#.
I don’t know how to nest the 0 and null statements together.
This is what I’ve got with an error still.
(IsNull(YTDSales4.Calculated_YTDSales4,0)-IsNull(YTDSales3.Calculated_YTDSales3,0)) / MAX(IsNull(YTDSales3.Calculated_YTDSales3,1))
think of your case statements (or anything else) like pieces. check for nulls first. isnull(blahblahblah) or (case when x=o then end) or whatever you need. Then take all of the piece out, and copy in to notebook or something and replace it all with X or something. Then do your next case statement around it. Then when you have all of the logic figured out replace your X’s with the pieces that you copied out.
It’s just like algebra.
2x+y=c
x = (102)
y = (30-5300)
replace x and with with the stuff and you end up with
2(102) + (30-5300) = C
You can make as many case statements within case statements as you want, they just get confusing.
BTW SQL will let you divide by NULL but not by zero.
If you divide by NULL you will get NULL.
If you do not want NULL as a result then you can check for NULL AFTER the division:
So you can use ISNULL and NULLIF to toggle your NULLs to zeros or any value to NULL.
An example to consider: ISNULL((76 / NULLIF( 0, 0 )),0)
RESULT = 0
case
when (OrderDtl.DiscountPercent) is null then (IsNull(OrderDtl.UnitPrice,0)- IsNull(OrderDtl.DiscountPercent,0))/1
when OrderDtl.DiscountPercent = 0 then (IsNull(OrderDtl.UnitPrice,0)- OrderDtl.DiscountPercent)/1
else (IsNull(OrderDtl.UnitPrice,0)- OrderDtl.DiscountPercent)/ OrderDtl.DiscountPercent
end
DiscountPercent is YTD3, and UnitPrice is YTD4
The first when checks for YTD3 being null.
The second checks for YTD being 0
The third (else) is when it is neither.
I don’t check for YTD3 being null in the 2nd when, or else.
EDIT:
Could have made the first two cases just one:
when IsNull(OrderDtl.DiscountPercent,0) =0 then (IsNull(OrderDtl.UnitPrice,0)- IsNull(OrderDtl.DiscountPercent,0))/1