Hi, I am trying to create the customer ageing report sql query logic but not getting the correct balance when going for the back dates instead of current date.
Below is the SQL query for the raw data and the buckets I have created in Power BI for the Due Date.
SELECT
custtrans.dataareaid AS Company,
custtrans.accountnum AS customerNo,
custtable.custgroup AS customerPostingGroup,
custtrans.currencycode AS currencyCode,
custtransopen.amountmst AS Balance,
--CASE
-- WHEN `` = 'Sales order' THEN custtrans.amountmst ELSE 0
-- END AS salesLCY,
custtrans.invoice AS documentNo,
custtrans.duedate AS DueDate,
custtrans.transtype_$label AS documentType,
custtrans.transdate AS postingDate,
custtrans.voucher AS customerLedgerEntryNo,
dirpartytable.name AS CustomerName
FROM custtrans
LEFT JOIN custtransopen ON
custtrans.accountnum = custtransopen.accountnum
AND custtrans.dataareaid = custtransopen.dataareaid
AND custtrans.recid = custtransopen.refrecid
LEFT JOIN custtable ON
custtrans.accountnum = custtable.accountnum AND
custtrans.dataareaid = custtable.dataareaid
LEFT JOIN dirpartytable ON
custtable.party = dirpartytable.recid