I have the following two queries, one with a number of invoices sorted by date and the other one with a number of receipts
Customer ID
Trans. Type
Trans. Date
N#
Value
Fiscal Year
1
Invoice
03/07/2021
1
20.00
2021
1
Invoice
03/07/2020
2
10.00
2020
1
Invoice
14/01/2020
3
50.00
2020
1
Invoice
21/10/2019
4
200.00
2019
2
Invoice
01/10/2018
5
99.00
2018
Customer ID
Trans. Type
Trans. Date
N#
Value
1
Receipt
04/12/2020
50
260.00
1
Receipt
03/12/2020
49
110.00
My goal is to add one column to the receipt query with the fiscal year the invoice refers to, starting from the more recent ones until the receipt value is reached. The year must be taken from the "Fiscal Year" column.
The following would be the result I want to achieve.
Customer ID
Trans. Type
Trans. Date
N#
Value
Fiscal Year
1
Receipt
04/12/2020
50
11.00
2021
1
Receipt
04/12/2020
50
60.00
2020
1
Receipt
04/12/2020
50
189.00
2019
1
Receipt
03/12/2020
49
11.00
2019
1
Receipt
03/12/2020
49
99.00
2018
I would like to achieve this with M but the exercise is not trivial for me because the value of the receipt can refer to multiple invoices and I don't know how to split it.
EDIT
The second query can have multiple records because there can be several receipts over a period of time for the same customer.
All or part of the first query records can be included in the second query (there cannot be any receipt without having an invoice in first place).
EDIT 2
The process combine invoices and receipts of the same customers
The process also assumes that the invoices paid first are the older ones therefore the older invoices are used up first and the invoice balance left is used up by the next receipt.
Related
I have a requirement to bill for the isoweeks of occupation in the previous month. The weeks are tiered such that...
(tier1) week1 = 23
(tier2) week2 = 28
(tier3) week3 = 35
(tier4) week4+ = 46
I have provided a sample of the table below:
The Weeks column counts the number of weeks in the previous month from TODAY() [2022-11-29]. Also note that 1 isoweek is subtracted from the total should occupation rollover from month to month to avoid duplicated billing from before the previous month-this has already been accounted for in the Weeks column, I also account for the current tier in the Tier column (I'm hoping that these helpers assist with final result)
If we look at Id 1, this entity has a total occupation of 4 isoweeks (2022-09-21 to 2022-10-21) however the intention is to bill 2 isoweeks in month 10. This entity is currently in tier 4. The result should be 81 (35+46).
If we look at Id 4, this entity has a total occupation of 13 isoweeks (2022-08-09 to 2022-10-31... it's still in occupation as at the end of month 10) however the intention is to bill 5 isoweeks in month 10. This entity is currently in tier 4. The result should be 230 (46+46+46+46+46).
If we look at Id 6, this entity has a total occupation of 3 isoweeks (2022-10-05 to 2022-10-19) the intention here is to bill 3 isoweeks in month 10. This entity is currently in tier 3. The result should be 86 (23+28+35).
I hope this makes sense. I greatly appreciate any and all help!
EDIT: I have attempted SUMPRODUCT using an array but either I am doing it incorrectly or the function isn't designed to work for my issue.
I have to bill a customer based on monthly usage however I'm only provided with a date range and total usage. I need to calculate the average daily usage, then calculate the number of days in each for the bill period, then multiply the days in month by the average to get the number of 'x' to bill the customer.
For example. I have two customers below and each has a different bill period and usage.
I'm given the data in Excel below. I'm struggling to build a formula that will give me A) the number of days in each month, B) the average use per day, C) the total amount used in each month. See the example below with how I calculate by hand.
Cell A1 Cell A2 Cell A3
9/5/2017 10/4/2017 83
Example:
Billing Period
Cust #1: 9/4/2017-10/4/2017 and usage is 85
Cust #2: 9/11/2017-10/11/2017 and usage is 1065
Cust #1
Sept Days is 27
Oct Days is 4
total days is 31
Ave use per day 2.7 (85 divided by 31)
Answer:
**Sept Usage is 74 Oct Usage is 11**
Cust #1
Sept Days is 20
Oct Days is 11
total days is 31
Ave use per day 34.35 (1065 divided by 31)
Answer:
**Sept Usage is 687 Oct Usage is 378**
I have the following Excel spreadsheet:
A B C D
1 Sales Price Sales Price Sales Price
2 January February March
3 Year 01 50 70 90
4 Year 02 50 60 40
5 Year 03 60 70 30
6 Year 04 40 60 50
7 Year 05 50 40 25
8
9 Majority Sales Price: 50 70 90
In Rows 3-7 you see the sales price of a product from the months January-March in 5 years (Year 01 - Year 05).
In Row 9 I want to select the sales price which has the majority within each month.
For example in January the sales price of 50 has the majority because it appears both in Year 01 and Year 02.
Please keep in mind the following criterias:
a) If there is no majority of a sales price the highest sales price should be picked. (Cell D9)
b) If two or more sales prices have the same majority the higher one should be picked. (Cell C9)
What formula do I need to get my desired result?
In cell B9 enter the following formula as an array, i.e. Ctrl+Shift+Enter:
{=IFERROR(MAX(MODE.MULT(B3:B7)), MAX(B3:B7))}
This uses MODE.MULT to find the modal value(s), which returns the result as an array. If there is more than one modal value, MAX returns the highest out of that array. If there is no modal value, MODE.MULT throws an error, hence the IFERROR statement which is used to find the max value in the error case.
Appreciate if anyone could advice how can I apply the Running-Total function for multiple measures?
I have 2 measures (Count) and (Revenue) by Month (Row) and Year (Column)
Product A Product B
2014 2015 2014 2015
Count | Revenue Count | Revenue Count | Revenue Count | Revenue
Jan 100
Feb 200
YTD 300
Mar 555
YTD 855
I tried with
running-total (currentMeasure for [Month], [Year], [Product Type])
but there is error claims that currentMeasure is not supported for QueryPackage.
In case I interpreted the message wrong, appreciate for your advice how can I apply the running-total correctly for multiple measures.
Thank you.
Count
running-total([Count] for [Product Type],[Year])
Revenue
running-total([Revenue] for [Product Type],[Year])
You don't specify month because it is in the row header. The 'for' clause indicates the grouping and the grouping comes from the column headers while the month defines the row grain. Another way to think about it is to put it into English:
Within each Product Type and Year combination, show me the accumulating total of each succeeding row broken out by Month.
Also, currentMeasure is used only in dimensionally-sourced reports, I believe.
I've got a table in Excel which is structure like so:
Month Date Time ID Name Currency Value
Jan 07/01/14 5 1234567 Ted GBP 500
Jan 10/01/14 12 1234567 Ted GBP 723
Feb 23/02/14 6 9877654 John GBP 300
Feb 10/02/14 10 1234567 Ted GBP 333
What I need to do is write a formula which basically returns be the total of Value where ID and Month are equal to whatever the lookup values are. For example, using the above I would say:
Find the total of Value where Month equals Jan and ID equals 1234567.
The answer in this case would be 1223.
Ive just tried
=SUMIFS(INPUT!H:H,INPUT!D:D='TRANS BY MID'!B2,INPUT!A:A='TRANS BY MID'!C1)
INPUT!H:H is my ID column
INPUT!D:D='TRANS BY MID'!B2 is the ID I want to use
INPUT!A:A is the Month column
TRANS BY MID'!C1 is Jan
To provide a working solution I simplified your question into one sheet. The data appears like this:
You can link your other sheet to the values shown in column J.
The formula is now this:
=SUMIFS(G:G,D:D,J1,A:A,J2)
The result is shown in J7: