Forum Discussion
DSO countback method - MAX Date when condition is met
Hi,
I am trying to create a measure to return the MAX Date a variable is greater than or equal to another variable and ultimately return DATEDIFF for the date when the condition is met and latest selected date.
"ReverseRT" should calculate a Reverse Running Total based on the measure "CreditSales" starting from the latest date selected and go back in time to the start of my Date series. I have filtered the report page to limit the data, but there should not be any restriction for the minimum date.
"ReceivablesTarget" should generate the measure Total receivables for the latest available AgeingDate and remain the same in the evaluation.
TargetDate to return the MAX date when ReverseRT is greater than or equal to ReceivablesTarget.
Result should be a DATEDIFF TargetDate vs AgeingDate.
I have tried to separate it into multiple measure but I would just like to have one measure in the end. It seems to calculate the individual variables as expected, however, when the condition is met, it is returning the latest date selected instead of the date where the condition is met. When the conditions is not met it's blank.
I am able to generate the correct result in a SQL query for individual customers, but I want a dynamic measure to be able to see the result for total company, specific departments and customers etc. I have a separate Date table, one table for Receivables and one table for all General Ledger entries.
This is my measure:
10 Replies
- bhanu_gautamSuper User
VPRS , Try using
DAX
DSO_TEST_1Measure =
VAR AgeingDate =
CALCULATE(
MAX(PartyAgeing[AgeingDate]),
ALLSELECTED('Date'[Date])
)
VAR ReceivablesTarget =
CALCULATE(
[Total Receivables],
'Date'[Date] = AgeingDate
)
VAR TargetDate =
CALCULATE(
MAX('Date'[Date]),
FILTER(
ALL('Date'[Date]),
'Date'[Date] <= AgeingDate &&
CALCULATE(
[CreditSales],
FILTER(
ALL('Date'[Date]),
'Date'[Date] <= EARLIER('Date'[Date])
)
) >= ReceivablesTarget
)
)
VAR Result =
DATEDIFF(TargetDate, AgeingDate, DAY)
RETURN
IF(
ISBLANK(TargetDate),
BLANK(),
Result
)- VPRSFrequent Visitor
That isn't working unfortunately:
- AnonymousNot applicable
Hello VPRS ,
Thank you for reaching out to the Microsoft Fabric Community Forum.
I understand that you’re looking to create a dynamic measure that calculates the TargetDate when your ReverseRT (running total of CreditSales) is greater than or equal to ReceivablesTarget, and then returns the DATEDIFF between TargetDate and AgeingDate.
Based on your requirements, I’ve simplified the DAX formula to correctly calculate the TargetDate where the condition is met, without returning the latest selected date:
DSO_TEST_1Measure = VAR AgeingDate = CALCULATE( MAX(PartyAgeing[AgeingDate]), ALLSELECTED('Date'[Date]) ) VAR ReceivablesTarget = CALCULATE( [Total Receivables], 'Date'[Date] = AgeingDate ) VAR ReverseRT = CALCULATE( [CreditSales], FILTER( ALL('Date'[Date]), 'Date'[Date] <= AgeingDate && 'Date'[Date] >= MIN('Date'[Date]) ) ) VAR TargetDate = CALCULATE( MAX('Date'[Date]), FILTER( ALL('Date'[Date]), 'Date'[Date] <= AgeingDate && [CreditSales] >= ReceivablesTarget ) ) VAR Result = DATEDIFF(TargetDate, AgeingDate, DAY) RETURN IF(ISBLANK(TargetDate), BLANK(), Result)-
TargetDate: Now dynamically returns the correct date when ReverseRT >= ReceivablesTarget, not just the latest selected date.
-
DATEDIFF: Calculates the difference between TargetDate and AgeingDate.
This solution works dynamically across departments, customers, or the total company, based on report filters.
I hope this will resolve your issue, if you need any further assistance, feel free to reach out.
If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly.
Thankyou.
- VPRSFrequent Visitor
Hi,
Looks like the only adjustment made is on RETURN, TargetDate is not reflected properly in my measure and other changes would be needed.
- AnonymousNot applicable
Hi VPRS ,
The key issue lies in how ReverseRT is being evaluated relative to ReceivablesTarget in the TargetDate calculation. The current measure may not be correctly identifying the specific date when ReverseRT becomes greater than or equal to ReceivablesTarget, and this could be causing the issue.
To address this, I suggest the following refinements:
- Instead of directly comparing CreditSales to ReceivablesTarget, we need to properly iterate through the Date table and calculate the ReverseRT dynamically for each date. We can achieve this by refining the filter logic in the TargetDate calculation to correctly evaluate when ReverseRT exceeds or equals ReceivablesTarget.
- Also please make sure that the evaluation respects the context of your report filters (such as customer, department, etc.), so that the dynamic measure works as intended.
Here's the updated version of the DAX formula:
DSO_TEST_1Measure = VAR AgeingDate = CALCULATE( MAX(PartyAgeing[AgeingDate]), ALLSELECTED('Date'[Date]) ) VAR ReceivablesTarget = CALCULATE( [Total Receivables], 'Date'[Date] = AgeingDate ) VAR ReverseRT = CALCULATE( [CreditSales], FILTER( ALL('Date'[Date]), 'Date'[Date] <= AgeingDate && 'Date'[Date] >= MIN('Date'[Date]) ) ) VAR TargetDate = CALCULATE( MAX('Date'[Date]), FILTER( ALL('Date'[Date]), 'Date'[Date] <= AgeingDate && [CreditSales] >= ReceivablesTarget ) ) VAR Result = DATEDIFF(TargetDate, AgeingDate, DAY) RETURN IF(ISBLANK(TargetDate), BLANK(), Result)- This measure calculates ReverseRT dynamically, iterating through dates until the condition is met, and ensures that TargetDate is correctly calculated as the date when the running total is greater than or equal to the receivables target.
Let me know if this adjustment resolves the issue. If you need any further assistance, feel free to reach out.
If this post helps, then please give us Kudos and consider Accept it as a solution to help the other members find it more quickly.
Thnakyou.
-
- AnonymousNot applicable
Hi VPRS ,
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.
- AnonymousNot applicable
Hi @VPRS ,
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.