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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
SebSchoon1
Post Patron
Post Patron

Use Date diff with dates obtaines from Userelationship

Hello Guys,

 

I have a huge fact Table which contains movement Type and movement Date.

 

I have created two columns to get The Order Dates, and Invoiced Dates here below the two formulas

 

Date Commandes fournisseurs =

if('Lignes de mouvement'[LIBELLE NATURE DE MOUVEMENT]="Commande fournisseur",

                 'Lignes de mouvement'[DATE PIECE],

                            BLANK())

AND 

 

Date Factures fournisseurs = 

if('Lignes de mouvement'[LIBELLE NATURE DE MOUVEMENT]="Facture fournisseur",

                       'Lignes de mouvement'[DATE PIECE],

                                             BLANK())

 

Then i have made some inactive relationships between Calendar[Date]

 

And these two columns  to know quantities ordered, and invoiced quantities.

 

Quantité de commande =

 

CALCULATE([Quantité],'Lignes de mouvement'[LIBELLE NATURE DE MOUVEMENT]="Commande fournisseur",

 

USERELATIONSHIP('Calendrier'[Date],'Lignes de mouvement'[Date Commandes fournisseurs]))
AND 
Quantité facturée =

CALCULATE([Quantité],'Lignes de mouvement'[LIBELLE NATURE DE MOUVEMENT]="Facture fournisseur",



USERELATIONSHIP(Calendrier[Date],'Lignes de mouvement'[Date Factures fournisseurs]))

 

Which provie me this result

 

SebSchoon1_0-1676388122884.png

 

I would like to get the Number of days between the two dates, Ordered and invoiced dates 

 

 

Even with this view it is ok 

 

SebSchoon1_1-1676388271577.png

 

 any ways to realize this?

 

many thanks for any help !! 😛

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

HI @SebSchoon1,

You can try to use the following measure formula to get the different based on current movement type and date:

Diff =
VAR currDate =
    MAX ( 'Lignes de mouvement'[DATE PIECE] )
VAR currType =
    SELECTEDVALUE ( 'Lignes de mouvement'[LIBELLE NATURE DE MOUVEMENT] )
VAR _start =
    SWITCH (
        currType,
        "Commande fournisseur", currDate,
        "Facture fournisseur",
            CALCULATE (
                MAX ( 'Lignes de mouvement'[DATE PIECE] ),
                FILTER (
                    ALLSELECTED ( 'Lignes de mouvement' ),
                    [LIBELLE NATURE DE MOUVEMENT] <> currType
                        && [DATE PIECE] < currDate
                )
            )
    )
VAR _end =
    SWITCH (
        currType,
        "Commande fournisseur",
            CALCULATE (
                MIN ( 'Lignes de mouvement'[DATE PIECE] ),
                FILTER (
                    ALLSELECTED ( 'Lignes de mouvement' ),
                    [LIBELLE NATURE DE MOUVEMENT] <> currType
                        && [DATE PIECE] > currDate
                )
            ),
        "Facture fournisseur", currDate
    )
RETURN
    DATEDIFF ( _start, _end, DAY )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

HI @SebSchoon1,

You can try to use the following measure formula to get the different based on current movement type and date:

Diff =
VAR currDate =
    MAX ( 'Lignes de mouvement'[DATE PIECE] )
VAR currType =
    SELECTEDVALUE ( 'Lignes de mouvement'[LIBELLE NATURE DE MOUVEMENT] )
VAR _start =
    SWITCH (
        currType,
        "Commande fournisseur", currDate,
        "Facture fournisseur",
            CALCULATE (
                MAX ( 'Lignes de mouvement'[DATE PIECE] ),
                FILTER (
                    ALLSELECTED ( 'Lignes de mouvement' ),
                    [LIBELLE NATURE DE MOUVEMENT] <> currType
                        && [DATE PIECE] < currDate
                )
            )
    )
VAR _end =
    SWITCH (
        currType,
        "Commande fournisseur",
            CALCULATE (
                MIN ( 'Lignes de mouvement'[DATE PIECE] ),
                FILTER (
                    ALLSELECTED ( 'Lignes de mouvement' ),
                    [LIBELLE NATURE DE MOUVEMENT] <> currType
                        && [DATE PIECE] > currDate
                )
            ),
        "Facture fournisseur", currDate
    )
RETURN
    DATEDIFF ( _start, _end, DAY )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.