Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
anamiac
Contributor
Contributor

Dates in Sum Expressions

Hello,

I have a table with three fields:  [Shipment Due Date], [Actual Shipped Date] and [Shipped Dollar Value].  I'm trying to create a chart with date as a dimension and 8 fields:

  1. The sum of the moneys expected/due to be shipped on that date
  2. The sum of the moneys actually shipped on that date
  3. For that date, the sum of the moneys expected to be shipped between that date and the first of the month.
  4. For that date, the sum of the moneys actually shipped between that date and the first of the month.
  5. The sum of the moneys expected/due to be shipped on that date 1 year ago
  6. The sum of the moneys actually shipped on that date 1 year ago
  7. For that date, the sum of the moneys expected to be shipped between that date and the first of the month 1 year ago.
  8. For that date, the sum of the moneys actually shipped between that date and the first of the month 1 year ago.

I have a master calendar, I'm attempting to use its 'Date' field as my dimension.  This is my expression for the first field:

Sum ({$<Date={[Shipment Due Date]}>} [Shipped Dollar Value])

But the field is returning 0 for all dates.  Anyone able to see what I'm doing wrong?

 

Labels (4)
4 Replies
Frank_Hartmann
Master II
Master II

please share qvw or rawdata

anamiac
Contributor
Contributor
Author


@Frank_Hartmann wrote:

please share qvw or rawdata


The qvw is 440 MB and I'm not sure if my company policies allow me to share it online.  I've attached the data as it appears after the load (the internal table).

anamiac
Contributor
Contributor
Author

This is solved, not by expressions, but by modifying my load script.  It was originally something like this:

ShipmentActual:
Load [Shipped Date Actual] AS [Actual Ship Date],
[Ship Date] As [Expected Ship Date],
IF($(_SysDBVersionNum)>=13.2,
([Shipped Picked Quantity] *
[Shipping Unit Price] *
[Shipping Rate $(_SysBaseCurrency)] /
[Shipping Price Unit Conversion]),
([Shipped Picked Quantity] *
[Shipping Unit Price] *
[Shipping Rate $(_SysBaseCurrency)] *
[Shipping Price Unit Conversion])
) as [Shipped Dollar Value],
%ShipReqLineKey
From $(_SysPathQVDDirectory)$(_SysQVDPrefix)ShippingRequests.qvd (qvd)
WHERE NOT IsNull([Shipped Picked Quantity]);

 

Here's what it is now:

ShipmentActual:
Load [Shipped Date Actual] AS [SA Shipment Date],
IF($(_SysDBVersionNum)>=13.2,
([Shipped Picked Quantity] *
[Shipping Unit Price] *
[Shipping Rate $(_SysBaseCurrency)] /
[Shipping Price Unit Conversion]),
([Shipped Picked Quantity] *
[Shipping Unit Price] *
[Shipping Rate $(_SysBaseCurrency)] *
[Shipping Price Unit Conversion])
) as [SA Actual Shipped Dollar Value],
%ShipReqLineKey,
month([Shipped Date Actual]) as [SA Shipment Month],
year([Shipped Date Actual]) as [SA Shipment Year]
From $(_SysPathQVDDirectory)$(_SysQVDPrefix)ShippingRequests.qvd (qvd)
WHERE NOT IsNull([Shipped Picked Quantity]);


Concatenate(ShipmentActual)
Load
[Ship Date] AS [SA Shipment Date],
IF($(_SysDBVersionNum)>=13.2,
([Shipped Picked Quantity] *
[Shipping Unit Price] *
[Shipping Rate $(_SysBaseCurrency)] /
[Shipping Price Unit Conversion]),
([Shipped Picked Quantity] *
[Shipping Unit Price] *
[Shipping Rate $(_SysBaseCurrency)] *
[Shipping Price Unit Conversion])
) as [SA Expected Shipped Dollar Value],
%ShipReqLineKey
From $(_SysPathQVDDirectory)$(_SysQVDPrefix)ShippingRequests.qvd (qvd)
WHERE NOT IsNull([Shipped Picked Quantity]);

Concatenate(ShipmentActual)
Load addyears([Shipped Date Actual],1) AS [SA Shipment Date],
IF($(_SysDBVersionNum)>=13.2,
([Shipped Picked Quantity] *
[Shipping Unit Price] *
[Shipping Rate $(_SysBaseCurrency)] /
[Shipping Price Unit Conversion]),
([Shipped Picked Quantity] *
[Shipping Unit Price] *
[Shipping Rate $(_SysBaseCurrency)] *
[Shipping Price Unit Conversion])
) as [SA PrevYear Actual Shipped Dollar Value],
%ShipReqLineKey
From $(_SysPathQVDDirectory)$(_SysQVDPrefix)ShippingRequests.qvd (qvd)
WHERE NOT IsNull([Shipped Picked Quantity]);

Concatenate(ShipmentActual)
Load
addyears([Ship Date],1) AS [SA Shipment Date],
IF($(_SysDBVersionNum)>=13.2,
([Shipped Picked Quantity] *
[Shipping Unit Price] *
[Shipping Rate $(_SysBaseCurrency)] /
[Shipping Price Unit Conversion]),
([Shipped Picked Quantity] *
[Shipping Unit Price] *
[Shipping Rate $(_SysBaseCurrency)] *
[Shipping Price Unit Conversion])
) as [SA PrevYear Expected Shipped Dollar Value],
%ShipReqLineKey
From $(_SysPathQVDDirectory)$(_SysQVDPrefix)ShippingRequests.qvd (qvd)
WHERE NOT IsNull([Shipped Picked Quantity]);

ShipmentActual2:
load
[SA Shipment Date] as [SA2 Shipment Date],
sum([SA Actual Shipped Dollar Value]) as [SA2 Actual Shipped Dollar Value],
sum([SA Expected Shipped Dollar Value]) as [SA2 Expected Shipped Dollar Value],
sum([SA PrevYear Actual Shipped Dollar Value]) as [SA2 PrevYear Actual Shipped Dollar Value],
sum([SA PrevYear Expected Shipped Dollar Value]) as [SA2 PrevYear Expected Shipped Dollar Value],
%ShipReqLineKey,
Day([SA Shipment Date]) as [SA2 Small Day]
resident ShipmentActual
group by [SA Shipment Date], %ShipReqLineKey;

let vMaxDays = 31;
for vOuterLoop = 0 to vMaxDays
for vInnerLoop = vOuterLoop to vMaxDays
DayMapping:
LOAD
$(vOuterLoop) as [smaller date],
$(vInnerLoop) as [larger date]
AUTOGENERATE(1);
next
next

left join (ShipmentActual2)
load
[smaller date] as [SA2 Small Day],
[larger date] as [SA2 Large Day]
Resident DayMapping;

Concatenate(ShipmentActual)
Load
date([SA2 Shipment Date] - [SA2 Small Day] + [SA2 Large Day]) as [SA Shipment Date],
[SA2 Actual Shipped Dollar Value] as [SA MTD Actual Shipped Dollar Value],
[SA2 Expected Shipped Dollar Value] as [SA MTD Expected Shipped Dollar Value],
[SA2 PrevYear Actual Shipped Dollar Value] as [SA MTD PrevYear Actual Shipped Dollar Value],
[SA2 PrevYear Expected Shipped Dollar Value] as [SA MTD PrevYear Expected Shipped Dollar Value],
%ShipReqLineKey,
month([SA2 Shipment Date]) as [SA Shipment Month],
year([SA2 Shipment Date]) as [SA Shipment Year]
Resident ShipmentActual2
where month([SA2 Shipment Date] - [SA2 Small Day] + [SA2 Large Day]) = Month([SA2 Shipment Date]);

drop table ShipmentActual2;
drop table DayMapping;
let vMaxDays=;
let vOuterLoop=;
let vInnerLoop=;

Brett_Bleess
Former Employee
Former Employee

Joseph, you can actually reduce the app quite a bit by using the File\Reduce Data\Keep Possible Values, but you need to make some selections first to be able to keep enough to still show the issue and data model etc.  The other piece you can use is in Settings\Document Properties\Scrambling tab to scramble values in a fields that are confidential etc.  

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.