The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
I've a data base, for Invoices paid on the last few months. I've Invoice Date, Invoice Creation Date, Invoice Due Date and Invoice Payment Date. In other table I've a calendar with Dates based on a cycle(Image below)
My use case is:
Invoice Number | Due Date | Payment Date | Invoice Date | Invoice Creation Date | Cycle Date |
039 | 2/28/2022 | 2/28/2022 | 2/18/2022 | 2/28/2022 | ? |
In summary I need to find the closest date related to my "Due Date". In that example I'll use Cycle 9, Cycle date 2/28/2022.
Solved! Go to Solution.
Hi @yagoframos
Please find attached sample file containing both options.
Cycle Date 2 =
MAXX (
TOPN (
1,
FILTER (
'Calendar',
'Calendar'[Month Number] = MONTH ( PaidInvoices[Due Date] )
&& PaidInvoices[Due Date] - 'Calendar'[Date] >= 0
),
PaidInvoices[Due Date] - 'Calendar'[Date],
ASC
),
'Calendar'[Date]
)
Hi @yagoframos
Assuming that you are creating a calculated column and that the Calendar table is unpivotted as suggested by @FreemanZ then you may try the following
Cycle Date =
MAXX (
TOPN (
1,
FILTER (
'Calendar',
'Calendar'[Month Number] = MONTH ( PaidInvoices[Due Date] )
),
ABS ( PaidInvoices[Due Date] - 'Calendar'[Date] ), ASC
),
'Calendar'[Date]
)
Awesome!!! That works for the next Cycle, and if I want to see the first one before the due date?
Hi @yagoframos
Please find attached sample file containing both options.
Cycle Date 2 =
MAXX (
TOPN (
1,
FILTER (
'Calendar',
'Calendar'[Month Number] = MONTH ( PaidInvoices[Due Date] )
&& PaidInvoices[Due Date] - 'Calendar'[Date] >= 0
),
PaidInvoices[Due Date] - 'Calendar'[Date],
ASC
),
'Calendar'[Date]
)
Thank you!!!
hi @yagoframos
the point might be to unpivot your table first to like:
Month | MonthNo | Cycle | Date |
Jan | 1 | Cycle1 | 1/4/2022 |
… |
then everything become easier.
That should't be a problem, my only concern is the best way to use the LOOKUP to find the right date.
User | Count |
---|---|
15 | |
12 | |
8 | |
7 | |
7 |
User | Count |
---|---|
24 | |
20 | |
12 | |
9 | |
7 |