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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.