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
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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.