I'm using Power Query to pull some billing information from a Sharepoint Folder. The fisrt image shows this table.
I then want to summarise this with a Pivot Table based on the billing period.
The second image shows my pivot table. I'm trying to create a measure 'Previous Month' that will give me the Total Charges for the previous month for each row - however I'm struggling. Please note - sometimes the different companies will be billed on different date periods - I still wish this to be based on the month the Bill Period End Date falls in.
This is the measure that I've created, but as you can see it only provides the 'Apr' value in the Grand Total.
=CALCULATE(
SUM(Billing[Total Charges excl. Vat]),
FILTER(Billing,
Billing[Billing Period End Date (Month Index)] = MAX(Billing[Billing Period End Date (Month Index)])-1)
)
I've searched several forums but cannot find an answer.
Invoice Date | Billing Period Start Date | Billing Period End Date | Company Name | Total Charges Excl VAT | Billing Period End Date (Year) | Billing Period End Date(Quarter) | Billing Period End Date (Month Index) | Billing Period End Date (Month) |
---|---|---|---|---|---|---|---|---|
06/02/2023 | 01/03/2023 | 31/03/2023 | Company A | 10.35 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company A | 10.35 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company A | 10.35 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company A | 10.35 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company B | 10.35 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company B | 10.35 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company B | 10.35 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company B | 10.35 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company A | 27.10 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company A | 27.10 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company A | 27.10 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company A | 27.10 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company B | 27.10 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company B | 27.10 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company B | 27.10 | 2023 | Qtr2 | 3 | Mar |
06/02/2023 | 01/03/2023 | 31/03/2023 | Company B | 11.10 | 2023 | Qtr2 | 3 | Mar |
05/05/2023 | 01/03/2023 | 31/03/2023 | Company B | 11.10 | 2023 | Qtr2 | 3 | Mar |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company B | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company B | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company A | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company B | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company B | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company B | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company B | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company A | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company A | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company A | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company A | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company B | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company B | 11.10 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company B | 29.00 | 2023 | Qtr2 | 5 | May |
05/05/2023 | 01/05/2023 | 31/05/2023 | Company B | 29.00 | 2023 | Qtr2 | 5 | May |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company A | 29.00 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company A | 29.00 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company A | 29.00 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company A | 29.00 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company B | 29.00 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company B | 29.00 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company B | 29.00 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company B | 29.00 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company A | 9.71 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company A | 9.71 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company A | 9.71 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company B | 9.71 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company B | 9.71 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company B | 9.71 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company B | 9.71 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company A | 9.71 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company A | 9.71 | 2023 | Qtr2 | 4 | Apr |
04/04/2023 | 01/04/2023 | 01/04/2023 | Company A | 9.71 | 2023 | Qtr2 | 4 | Apr |
Here you go.
=VAR p = CALCULATE(MAX(Billing[Billing Period End Date (Month Index)])-1)
VAR s = CALCULATE( SUM(Billing[Total Charges Excl VAT]),FILTER(ALL(Billing),Billing[Billing Period End Date (Month Index)] = p))
RETURN
IF(HASONEVALUE(Billing[Billing Period End Date (Month Index)]), s)