I’m trying to create a table for analyzing part seasonality. I created 2 BAQ calculated fields to group by Year & Month, and another calculated sum to show monthly order qty. I need to include the months with 0’s, rather than having the BAQ’s SUM skip them.
How can I show the null rows?
I think I’m close, but here’s what didn’t work:
1 ○ COALESCE(sum(OrderDtl.OrderQty),0)
2 ○ ISNULL (sum (OrderDtl.OrderQty), 0)
3 ○ ISNULL (sum
(case
when OrderDtl.OrderQty > 0 then OrderDtl.OrderQty
else 0
end),0)
4 ○ IF (ISNULL(sum(OrderDtl.OrderQty)), 0, sum(OrderDtl.OrderQty))
The first 3 pass the error check, and the last does not.
Hi Nate, I tried that, and it errors out with an extra comma somewhere. It seems like it needed and extra ) at the end, but that didn’t fix it either. can’t find the issue, though!
Respaced it for visual clarity and added the ), but still get that same error:
@bordway - Thanks. I gave it a try, but this didn’t add the 0 records either.
Thanks for trying. Seems like using ISNULL to add the 0 should work, with or without a case. Other’s have done it successfully in BAQ for calculations.
I tried adding a +1 to the formula, but that also doesn’t show the row, so maybe it’s not a null issue, and instead it’s a join issue. What if there’s no row to fill?
Thanks for jumping in, Haso. I tried the left join, but still no July 2019 with a 0.
I also tried the sum outside of the case, but no dice either.
Still think it might be related to not having any data at all, so there is no row to start with. Maybe it’s due to the other GroupBy’s for the date columns? How would BAQ know to even create the ‘2019-07’ row if there is no order detail with that record to create that calculated field? Jeez, I don’t know where to start with that one! Rabbit holes…
a left join will not magically create a July, you must have an order in July. You could start with the table FiscalPer thats assuming you have 12 periods, for us it wouldn’t work. Maybe Company Calendar or some other table that has Months, otherwise you will have to build one with FOR XML.
Haso,
Awesome!!! When I created a new test BAQ by adding Fiscal Calendar first, and then OrderDtl, the missing rows showed up with a left join. TY!
Yet when I try to add Fiscal Calendar 2nd, after OrderDtl, no matter what, the missing rows do not appear, even if I do a full outer join.
Do I need to rebuild the BAQ, making sure to add Fiscal Calendar before OrderDtl? Is there a shortcut way of making that change without needing to delete OrderDtl and re-creating everything associated with it?
You just made me realize that’s why the BAQ would seemingly just randomly not like my syntax in a calculated field. I’ve made a bad habit of calling calculated fields things like Year, Month, etc. I just learned today that Row is another one that you need to not use.
It’s deceptive because (a) it allows it and (b) it works sometimes. But if you calculate off of a calculated field in the same subquery, for example, it calls it by Row rather than Calculated_Row
And probably many other reasons that are clearer to SQL people.