Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
awff
Helper III
Helper III

Need help with loyal and reactivated DAX!

Hello fellow PBI'ers

 

I'm trying to find the next latest date based on two columns. Basically, the Islost2 column should show the next LATEST start date greater than the previous end date and if next latest start date = end date , then return that start date. Essentially opposite of the function - EARLIER(). 

 

awff_1-1647846873405.png

The results should be as below (simplified for this post):

 

Start DateEnd dateResult

21-Dec-16

21-Dec-1703-Jul-18
23-May-1723-May-1803-Jul-18
16-Oct-1716-Oct-1830-Nov-18
13-Nov-1730-Nov-1830-Nov-18
03-Jul-1803-Jul-1930-Nov-19
30-Nov-1830-Nov-1930-Nov-19
30-Nov-1911-Jun-2023-Feb-21
23-Feb-2123-Feb-2201-Apr-21
01-Apr-2123-Feb-22 

 

Below is the DAX used for "Islost2" which i know is incorrect as it is similar to the EARLIER() fuction; and hoping i could get some assistance tweaking it.

 

Islost2 = 
var Acc_Id = '_fact (Quote)'[AccountID]
var End_date = '_fact (Quote)'[End_Date__c]
var _current=
'_fact (Quote)'[End_Date__c]
var _next= 
CALCULATE(
    MAX('_fact (Quote)'[Start_Date__c]),
    FILTER(
        ALL('_fact (Quote)'),
        '_fact (Quote)'[QuoteStatus (invoiceRequested)] = "Invoiced" &&
        '_fact (Quote)'[AccountID] = Acc_Id &&
       '_fact (Quote)'[start_Date__c] < End_date))
return
_next

 

 

Hopefully this makes sense...

 

Thank you in advance!

 

3 REPLIES 3
awff
Helper III
Helper III

Hi @amitchandak 

Is there a way where if there is no longer a start date greater than the end date, instead of the blanks, it returns the latest end date? In this case 23-Feb-22 instead of blank?

 

This would allow me to use SWITCH(TRUE() function to determine lost customers is greater than 365 days between the end date and next start date or of the last end date is greater than today().

awff_0-1647903361842.png

 

amitchandak
Super User
Super User

@awff , Based on what I got, Try like

 

Islost2 =
var Acc_Id = '_fact (Quote)'[AccountID]
var End_date = '_fact (Quote)'[End_Date__c]
var _current=
'_fact (Quote)'[End_Date__c]
var _next=
CALCULATE(
Min('_fact (Quote)'[Start_Date__c]),
FILTER(
ALL('_fact (Quote)'),
'_fact (Quote)'[QuoteStatus (invoiceRequested)] = "Invoiced" &&
'_fact (Quote)'[AccountID] = Acc_Id &&
'_fact (Quote)'[start_Date__c] > End_date))
return
_next

 

 

or

 

Islost2 =
var Acc_Id = '_fact (Quote)'[AccountID]
var End_date = '_fact (Quote)'[End_Date__c]
var _current=
'_fact (Quote)'[End_Date__c]
var _next=
CALCULATE(
Min('_fact (Quote)'[Start_Date__c]),
FILTER(
ALL('_fact (Quote)'),
'_fact (Quote)'[QuoteStatus (invoiceRequested)] = "Invoiced" &&
'_fact (Quote)'[AccountID] = Acc_Id &&
'_fact (Quote)'[start_Date__c] >= End_date))
return
_next

Knew it was close! Helpful as always thank you.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.