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
emf_efab
Frequent Visitor

Getting the date of following ID to calculate (datediff) between initial date and final date

I need to get the date of the next ID in the same Order (Pedido), to make afterwards a DateDiff and have as a result the days spended in that state (Estado). For example I need to fill up the blue column (Dia_Sig) with the "correct" date. In ID "31" I should have data as shown, plus "Dia_Sig" 20/02/2021, to then calculate the days and have a next column with "18" as a result.

I need to know how many days I spend in each "Estado", having as final result that the Order (Pedido) lasted 38 days, between 01/02/2021 (Initial Date) and the (Last Date) 11/03/2021. I have the PBIX, and Excel file to attach and send, for better understanding.

 

emf_efab_0-1627999193457.png

 

1 ACCEPTED SOLUTION

Since you want to create a calculated column then you can write it as follows:

Dia_Sig = 
Var SelectedID = 'Control Emails'[ID]
RETURN
CALCULATE (
    Min ( 'Control Emails'[Fecha] ),
    FILTER (
        ALLEXCEPT ( 'Control Emails', 'Control Emails'[Pedido#] ),
        'Control Emails'[ID] > SelectedID
    )
)

The measure to calculate he duration could be:

Duration = 
IF (
    HASONEVALUE ( 'Control Emails'[Pedido#] ),
    DATEDIFF (
        MIN ( 'Control Emails'[Fecha] ),
        MAX ( 'Control Emails'[Dia_Sig] ),
        DAY
    )
)

 

m_refaei_0-1628127639706.png

(last column)

 

m_refaei_1-1628127677954.png

Please check the adjusted file.

View solution in original post

7 REPLIES 7
emf_efab
Frequent Visitor

The pbix Order Ctrl and the Excel Testing 

Since you want to create a calculated column then you can write it as follows:

Dia_Sig = 
Var SelectedID = 'Control Emails'[ID]
RETURN
CALCULATE (
    Min ( 'Control Emails'[Fecha] ),
    FILTER (
        ALLEXCEPT ( 'Control Emails', 'Control Emails'[Pedido#] ),
        'Control Emails'[ID] > SelectedID
    )
)

The measure to calculate he duration could be:

Duration = 
IF (
    HASONEVALUE ( 'Control Emails'[Pedido#] ),
    DATEDIFF (
        MIN ( 'Control Emails'[Fecha] ),
        MAX ( 'Control Emails'[Dia_Sig] ),
        DAY
    )
)

 

m_refaei_0-1628127639706.png

(last column)

 

m_refaei_1-1628127677954.png

Please check the adjusted file.

Thank you very much, I can now go forward, with this help. Regards!!!

emf_efab
Frequent Visitor

 I need to calculate the Fecha_Modif as it is shown in the picture...that should be Dia_Sig, not the one I have now in blue. That should be the next (Initial) Date, for the next ID of the same Order (Pedido#). I shouldn't have Blanks!! >> Id 11 should be 01/02/2021, and Id 31 20/02/2021  

 

emf_efab_0-1628094231386.png

 

emf_efab
Frequent Visitor

It doesn't work or I don't understand what you want to do...Which should be the way to attach the report, and excel file. Sorry I am new in the Forum, and don't know to work with it.

 

You may upload the file to your OneDrive or GoogleDrive and share the link here

Mohammad_Refaei
Solution Specialist
Solution Specialist

You can try this calculated column:

Dia_Sig =
CALCULATE (
    MAX ( [Fecha] ),
    FILTER (
        ALL ( MyTable ),
        MyTable[Pedido] = MyTable[Pedido]
            && MyTable[Fecha] > MyTable[Fecha]
    )
)

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.

Top Solution Authors