Hello @Shane1,
The reason why the solution got more complexed is because neither you separated the columns with datetime data type into two different columns i.e., one column for date and other one for time nor you created a proper data model i.e., star schema.
So the first thing that I did now is, to split the columns and parse them into two separate columns and then convert the flat file into a star schema. Below are the screenshots of the data model provided for the reference -
Now, I wrote the following measures to achieve the results as you had mentioned in your statement/scenario i.e., “October will have an amount of 46,603.58/- and September will have an amount of 4,095.00/-. And therefore, the correct number when selecting Oct - 2022 in the slicer should be 50,968.58/-.” Below are the measures alongwith the screenshot of the final results provided for the reference -
1. Total Amounts - (Optional) =
SUM( GL[AED Amount] )
2. Net Receivables =
VAR _Max_Date =
CALCULATE( MAX( Dates[Date] ) ,
ALLSELECTED( Dates ) )
VAR _Results =
SUMX(
FILTER(
ADDCOLUMNS(
SUMMARIZE(
GL ,
Entities[Unique Customer Code] ,
DebDateRef[Unique Debit Reference] ,
GL[Due Date] ,
GL[Document Date] ,
GL[Debit Date] ) ,
"@Days_Overdue" ,
IF( GL[Document Date] <= _Max_Date ,
DATEDIFF( GL[Due Date] , _Max_Date , DAY ) ) ,
"@Amounts" ,
CALCULATE( SUM( GL[AED Amount] ) ) ) ,
GL[Document Date] <= _Max_Date &&
[@Days_Overdue] <> BLANK() ) ,
[@Amounts] )
RETURN
_Results
3. Days Overdue For Aging =
VAR _Max_Selected_Date =
CALCULATE( MAX( Dates[Date] ) ,
ALLSELECTED( Dates ) )
VAR _Current_Document_Date =
SELECTEDVALUE( GL[Document Date] )
VAR _Current_Due_Date =
SELECTEDVALUE( GL[Due Date] )
VAR _Results =
IF(
_Current_Document_Date <= _Max_Selected_Date &&
[2. Net Receivables] > 0 ,
DATEDIFF( _Current_Due_Date , _Max_Selected_Date , DAY ) )
RETURN
_Results
4. Days Overdue For Matrix =
VAR _Max_Date =
CALCULATE( MAX( Dates[Date] ) ,
ALLSELECTED( Dates ) )
VAR _Results =
IF( ISINSCOPE( Entities[Unique Customer Code] ) ,
SUMX(
FILTER(
ADDCOLUMNS(
SUMMARIZE(
GL ,
Entities[Unique Customer Code] ,
DebDateRef[Unique Debit Reference] ,
GL[Due Date] ,
GL[Document Date] ,
GL[Debit Date] ) ,
"@Days_Overdue" ,
IF( GL[Document Date] <= _Max_Date ,
DATEDIFF( GL[Due Date] , _Max_Date , DAY ) ) ) ,
GL[Document Date] <= _Max_Date &&
[@Days_Overdue] <> BLANK() ) ,
[@Days_Overdue] ) )
RETURN
_Results
5. Aged Receivables Per Group =
CALCULATE( [2. Net Receivables] ,
FILTER( Entities ,
COUNTROWS(
FILTER( 'Aged Debtor Groups' ,
[3. Days Overdue For Aging] >= 'Aged Debtor Groups'[Min] &&
[3. Days Overdue For Aging] <= 'Aged Debtor Groups'[Max] ) ) > 0 ) )
6. Ranking =
VAR _Max_Selected_Date =
CALCULATE( MAX( Dates[Date] ) ,
ALLSELECTED( Dates ) )
VAR _Current_Document_Date =
SELECTEDVALUE( GL[Document Date] )
VAR _Current_Unique_Debit_Reference =
SELECTEDVALUE( GL[Unique Debit Reference] )
VAR _Current_Due_Date =
SELECTEDVALUE( GL[Due Date] )
VAR _Results =
IF( _Current_Document_Date < _Max_Selected_Date ,
RANKX(
FILTER( ALLSELECTED( GL ) ,
GL[Unique Debit Reference] = _Current_Unique_Debit_Reference &&
GL[Document Date] <= _Max_Selected_Date ) ,
CALCULATE(
SELECTEDVALUE( GL[Debit Date] ) +
SELECTEDVALUE( GL[Debit Time] ) ) , ,
DESC ,
DENSE ) )
RETURN
IF( NOT ISBLANK( [2. Net Receivables] ) &&
ISINSCOPE( Entities[Unique Customer Code] ) ,
_Results )
7. Running Totals =
VAR _Current_Unique_Debit_Reference =
SELECTEDVALUE( GL[Unique Debit Reference] )
VAR _Current_Debit_Date =
SELECTEDVALUE( GL[Debit Date] ) + SELECTEDVALUE( GL[Debit Time] )
VAR _Ranking =
[6. Ranking]
VAR _Filtered_Table =
FILTER( ALLSELECTED ( GL ) ,
GL[Unique Debit Reference] = _Current_Unique_Debit_Reference &&
GL[Debit Date] + GL[Debit Time] <= _Current_Debit_Date &&
NOT ( ISBLANK ( [6. Ranking] ) ) )
VAR _Results =
SUMX(
_Filtered_Table ,
GL[AED Amount] )
RETURN
IF( NOT ISBLANK( [2. Net Receivables] ) &&
[6. Ranking] = 1 &&
ISINSCOPE( Entities[Unique Customer Code] ) ,
_Results )
I’m also attaching the working of the PBIX file for the reference purposes.
Hoping this meets your requirements.
Important Notes: -
1). Measure No. 1 is optional.
2). In my case, I achieved the solution by writing the measures from Measure No.'s 2 to 5.
3). Measure No.'s 6 and & 7 are written just because they were there in your original PBIX file and you were trying to create ananlysis based on them. In my case, they were not even required. The way these measures are written by you, they broke the data lineage and therefore, you were not able to analyse them in the aging table as well as not able to fetch those cumulative numbers where “Ranking = 1”.
4). The results while selecting the month “Oct 2022” in the slicer will be “50,698.58/-” and not “50,968.58/-”. That is,
for “Sep 2022 = 4,095.00/-” (+) “Oct 2022 = 46,603.58/-” (=) “Total Receivables = 50698.58/-”
5). In case, you would like to know/learn more about data modelling or DAX in-depth. I would sincerely recommend to please go through the EDNA education portal.
Thanks and Warm Regards,
Harsh
Accounts Receivables - Harsh.pbix (173.2 KB)