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
RegionH
Helper I
Helper I

Calculate if order is too late or on time based on parameter

Hi

 

My datamodel has two tables called 'Indkøbsordrer' and 'Varemodtagelser'. The two tables are connected on [Ordre nøgle] in a one to many relationship.

 

I'm trying to calculate if an order is "Too late" or "On time" based on the following DAX-formula.

 

Ordrer Punktlighed = 
if(
    ISEMPTY(
        Filter(
            CALCULATETABLE(
            'Varemodtagelser', ALLEXCEPT('Varemodtagelser','Varemodtagelser'[Indkøbsordrenummer])),
            sum(Varemodtagelser[Modtagelsesdato])-'Leveringstidsjustering'[Leveringstidsjustering Value]-sum(Varemodtagelser[Statistikdato]) > 0
        )
    ),
    "On time",
    "Late"
)

 

The formula is working fine. But now I would like to distinguish between the value of the column 'Indkøbsordrer'[Indkøbsbilagsart].  If the value in the row is equal to "ZLM" or "ZCD, then use the parameter as is. But if the value is diffent, then use the value 5 days.

 

So I wrote this formula, but it is not working, because when I use this measure in another measure to calculate the sum of "Delayed orders" I get 2.484. The same result as the original formula.

 

Z_Ordrer_Punktlighed_Bilagsart = 
IF(
    ISEMPTY(
        FILTER(
            CALCULATETABLE(
                'Varemodtagelser',
                ALLEXCEPT('Varemodtagelser', 'Varemodtagelser'[Indkøbsordrenummer])
            ),
            SUM('Varemodtagelser'[Modtagelsesdato]) - 
            IF(
                RELATED('Indkøbsordrer'[Indkøbsbilagsart]) = "ZLM" || RELATED('Indkøbsordrer'[Indkøbsbilagsart]) = "ZCD",
                'Leveringstidsjustering'[Leveringstidsjustering Value],
                5
            ) - 
            SUM('Varemodtagelser'[Statistikdato]) > 0
        )
    ),
    "On time",
    "Late"
)

 

I hope someone will take a look at the formula and maybe help me correct it?

 

RegionH_0-1710771259102.png

 

Thanks in advance.

 

Best regards

Morten  

1 ACCEPTED SOLUTION

Thank you for answering my question. The reason for using related is that the table 'Indkøbsordrer' has the information about [Indkøbsbilagsart]. This information is not represented in the table 'Varemodtagelser'. 

 

I wrote another DAX-formula which solved my problem. 

Z_ForsinkedeBilagsarter = 
VAR Forsinkelser_ZLM_ZCD =
    CALCULATE (
        DISTINCTCOUNT ( 'Indkøbsordrer'[Indkøbsordrenummer] ),
        FILTER (
            'Varemodtagelser',
            (
                'Varemodtagelser'[Modtagelsesdato]
                - 'Leveringstidsjustering'[Leveringstidsjustering Value]
                - 'Varemodtagelser'[Statistikdato]
            ) > 0
                && (
                    RELATED ( 'Indkøbsordrer'[Indkøbsbilagsart] ) = "ZLM"
                    || RELATED ( 'Indkøbsordrer'[Indkøbsbilagsart] ) = "ZCD"
                )
        )
    )
VAR Forsinkelser_Andre =
    CALCULATE (
        DISTINCTCOUNT ( 'Indkøbsordrer'[Indkøbsordrenummer] ),
        FILTER (
            'Varemodtagelser',
            (
                'Varemodtagelser'[Modtagelsesdato]
                - 5
                - 'Varemodtagelser'[Statistikdato]
            ) > 0
                && NOT (
                    RELATED ( 'Indkøbsordrer'[Indkøbsbilagsart] ) = "ZLM"
                    || RELATED ( 'Indkøbsordrer'[Indkøbsbilagsart] ) = "ZCD"
                )
        )
    )
RETURN
    Forsinkelser_ZLM_ZCD + Forsinkelser_Andre

View solution in original post

2 REPLIES 2
lbendlin
Super User
Super User

what's your reasoning for using RELATED in a measure?

 

Z_Ordrer_Punktlighed_Bilagsart = 
IF(
    ISEMPTY(
        FILTER(
            CALCULATETABLE(
                'Varemodtagelser',
                ALLEXCEPT('Varemodtagelser', 'Varemodtagelser'[Indkøbsordrenummer])
            ),
            SUM('Varemodtagelser'[Modtagelsesdato]) - 
            IF('Indkøbsordrer'[Indkøbsbilagsart]) IN { "ZLM" ,"ZCD" },
                'Leveringstidsjustering'[Leveringstidsjustering Value],5
            ) - 
            SUM('Varemodtagelser'[Statistikdato]) > 0
        )
    ),
    "On time",
    "Late"
)

 

You could also use Countrows instead of IF(ISEMPTY).

Thank you for answering my question. The reason for using related is that the table 'Indkøbsordrer' has the information about [Indkøbsbilagsart]. This information is not represented in the table 'Varemodtagelser'. 

 

I wrote another DAX-formula which solved my problem. 

Z_ForsinkedeBilagsarter = 
VAR Forsinkelser_ZLM_ZCD =
    CALCULATE (
        DISTINCTCOUNT ( 'Indkøbsordrer'[Indkøbsordrenummer] ),
        FILTER (
            'Varemodtagelser',
            (
                'Varemodtagelser'[Modtagelsesdato]
                - 'Leveringstidsjustering'[Leveringstidsjustering Value]
                - 'Varemodtagelser'[Statistikdato]
            ) > 0
                && (
                    RELATED ( 'Indkøbsordrer'[Indkøbsbilagsart] ) = "ZLM"
                    || RELATED ( 'Indkøbsordrer'[Indkøbsbilagsart] ) = "ZCD"
                )
        )
    )
VAR Forsinkelser_Andre =
    CALCULATE (
        DISTINCTCOUNT ( 'Indkøbsordrer'[Indkøbsordrenummer] ),
        FILTER (
            'Varemodtagelser',
            (
                'Varemodtagelser'[Modtagelsesdato]
                - 5
                - 'Varemodtagelser'[Statistikdato]
            ) > 0
                && NOT (
                    RELATED ( 'Indkøbsordrer'[Indkøbsbilagsart] ) = "ZLM"
                    || RELATED ( 'Indkøbsordrer'[Indkøbsbilagsart] ) = "ZCD"
                )
        )
    )
RETURN
    Forsinkelser_ZLM_ZCD + Forsinkelser_Andre

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.