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
kaylastarr
Advocate V
Advocate V

Need help calculating % of on time shipments by month

Hello Helpful People,

 

I have the following dataset

Supplier NameMaterial NumberStat. Delv DateG/R DatePerformance
LEONI FIBER OPTICS INC222-3175008/5/20228/26/2022Late
LEONI FIBER OPTICS INC030-0010008/5/20229/19/2022Late
LEONI FIBER OPTICS INC030-0011008/8/20228/1/2022Early
LEONI FIBER OPTICS INC460-1028008/12/20221/1/1901Late
LEONI FIBER OPTICS INC460-1024008/15/202210/21/2022Late
LEONI FIBER OPTICS INC460-1024008/24/20221/1/1901Late
LEONI FIBER OPTICS INC030-0010009/6/20229/26/2022Late
LEONI FIBER OPTICS INC030-0009009/6/20229/19/2022Late
LEONI FIBER OPTICS INC222-3179009/9/202210/12/2022Late
LEONI FIBER OPTICS INC460-1028009/22/20221/1/1901Late
LEONI FIBER OPTICS INC460-11380110/3/20221/1/1901Late
LEONI FIBER OPTICS INC030-00090010/5/202210/12/2022Late
LEONI FIBER OPTICS INC030-00100010/5/202210/3/2022Early
LEONI FIBER OPTICS INC030-00110010/14/202210/12/2022Early
LEONI FIBER OPTICS INC222-27250010/17/202210/24/2022Late
LEONI FIBER OPTICS INC222-31750010/20/20221/1/1901Late
LEONI FIBER OPTICS INC222-31790010/21/202210/18/2022Early
LEONI FIBER OPTICS INC030-00080010/24/202210/24/2022Early
LEONI FIBER OPTICS INC222-27210010/26/202210/24/2022Early
LEONI FIBER OPTICS INC222-27210010/26/202210/24/2022Early
LEONI FIBER OPTICS INC222-27220010/26/20221/1/1901Late
LEONI FIBER OPTICS INC222-27220010/26/20221/1/1901Late
LEONI FIBER OPTICS INC460-10240010/27/20221/1/1901Late
LEONI FIBER OPTICS INC460-10240010/31/20221/1/1901Late

 

I am trying to create a line plot that shows the percentage of materials that are shipped "Early" each month. I am using the below measure to calculate the %:

On Time Shipments = CALCULATE(COUNTROWS(Suppliers),OR(Suppliers[Performance]="On Time",Suppliers[Performance]="Early")=True)/CALCULATE(COUNTROWS(Suppliers),Suppliers[Performance]<>"Not Delivered Yet")
 
This graphs correctly EXCEPT when ALL of the lines are late. Then it has no data, I would like it to have 0 if all the materials are late. 
 
Any help is appreciated. 
 
Here is the graph that results (as you can see September has no data ploted due to everything being late)

image.png

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

Hi @kaylastarr ,

Try adding zeros to the numerator, like this:

On Time Shipments = 
VAR _ON_TIME = 
CALCULATE (
    COUNTROWS ( Suppliers ),
    OR ( Suppliers[Performance] = "On Time", Suppliers[Performance] = "Early" ) = TRUE
) + 0
VAR _DELIVERED =
    CALCULATE (
        COUNTROWS ( Suppliers ),
        Suppliers[Performance] <> "Not Delivered Yet"
    )
VAR _RESULT = DIVIDE(_ON_TIME,_DELIVERED)
RETURN
_RESULT

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

4 REPLIES 4
v-cgao-msft
Community Support
Community Support

Hi @kaylastarr ,

Try adding zeros to the numerator, like this:

On Time Shipments = 
VAR _ON_TIME = 
CALCULATE (
    COUNTROWS ( Suppliers ),
    OR ( Suppliers[Performance] = "On Time", Suppliers[Performance] = "Early" ) = TRUE
) + 0
VAR _DELIVERED =
    CALCULATE (
        COUNTROWS ( Suppliers ),
        Suppliers[Performance] <> "Not Delivered Yet"
    )
VAR _RESULT = DIVIDE(_ON_TIME,_DELIVERED)
RETURN
_RESULT

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

This worked! without pulling in unnecessary 0's thank you so much!

djurecicK2
Super User
Super User

Hi @kaylastarr ,

You can add an IF statement to the measure.

 

Something like this:

 

On Time Shipments =
VAR CountofNonLateShipments =
    CALCULATE (
        COUNTROWS ( Suppliers ),
        OR ( Suppliers[Performance] = "On Time", Suppliers[Performance] = "Early" ) = TRUE
    )
RETURN
    IF (
        ISBLANK ( CountofNonLateShipments ),
        0,
        CALCULATE (
            COUNTROWS ( Suppliers ),
            OR ( Suppliers[Performance] = "On Time", Suppliers[Performance] = "Early" ) = TRUE
        )
            / CALCULATE (
                COUNTROWS ( Suppliers ),
                Suppliers[Performance] <> "Not Delivered Yet"
            )
    )

Please mark as accepted solution if this has resolved the issue.

I have tried adding the IF statement before and it ends up pulling in ANY material that is on the list as 0 instead of just the ones for that month. But the solution by Gao above works.

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.