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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Sully7518
Regular Visitor

Measure to calculate but ignore if row result of calculations less than zero and aggregate the rest

Hi, need help with the following please. My data comes to me in the below layout (I have simplified it for this forums purpose):

 

I have a query which returns a table like the one below:

 

Batch NumberBatch StageType of TimeQty Time (minutes)
ABCD11111MixingActual Duration100
ABCD11111MixingPlanned Duration50
ABCD22222MixingActual Duration200
ABCD22222MixingPlanned Duration300
AAAA00000MixingActual Duration60
AAAA00000MixingPlanned Duration50
ABBB99999StiringActual Duration100
ABBB99999StirringPlanned Duration110
CCCC10000StirringActual Duration120
CCCC10000StirringPlanned Duration110

 

What I need is a measure which calculates each Batch Actual vs each Batch Planned (from the type of Time Column) on a row by row individual basis. It then needs to ignore/zero any calculation which return less than zero result and only aggregate the one with a positive result.

The calcuation would be:  Actual Duration - Planned Duration = Net Lost time

 

This is what it would look like if it was in the correct form.

 

Batch NumberBatch StageActual DurationPlanned DurationSum ResultAction
ABCD11111Mixing1005050Keep
ABCD22222Mixing200300-100Ignore/zero
AAAA00000Mixing605010Keep
ABBB99999Stirring100110-10Ignore/zero
CCCC10000Stirring12011010Keep

 

If I then put the following into a Bar Chart = Y - Axis [Batch Stage] and X-Axis [Sum Result - i.e. the measure I am asking for

 

The result would return the below - 

 

Mixing Lost Time =  60

Stirring Lost Time = 10

 

I would really appreciate someones help. Changing the layout of the data would be difficult with the amount of records.

 

Many thanks in advance.

 

Sully.

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @Sully7518 

try to plot a visual with the [Batch Stage] column and a measure like:

LostTime = 
VAR _table =
ADDCOLUMNS(
    SUMMARIZE(
        TableName,
        TableName[Batch Number],
        TableName[Batch Stage]
    ),
    "SumResult",
    CALCULATE(
        MINX(
            FILTER(TableName, TableName[Type of Time] = "Actual Duration"),
            TableName[Qty Time (minutes)]
        ) -
        MINX(
            FILTER(TableName, TableName[Type of Time] = "Planned Duration"),
            TableName[Qty Time (minutes)]
        )  
    )
)
RETURN
SUMX(
    FILTER(_table, [SumResult]>0),
    [SumResult]
)

 

it worked like:

FreemanZ_0-1677725909458.png

 

View solution in original post

2 REPLIES 2
Sully7518
Regular Visitor

Hi @FreemanZ ,

 

Fanstastic, it worked perfectly!! You're an absolute star. Thank you so much for taking the time to help me, I really appreciate it!

FreemanZ
Super User
Super User

hi @Sully7518 

try to plot a visual with the [Batch Stage] column and a measure like:

LostTime = 
VAR _table =
ADDCOLUMNS(
    SUMMARIZE(
        TableName,
        TableName[Batch Number],
        TableName[Batch Stage]
    ),
    "SumResult",
    CALCULATE(
        MINX(
            FILTER(TableName, TableName[Type of Time] = "Actual Duration"),
            TableName[Qty Time (minutes)]
        ) -
        MINX(
            FILTER(TableName, TableName[Type of Time] = "Planned Duration"),
            TableName[Qty Time (minutes)]
        )  
    )
)
RETURN
SUMX(
    FILTER(_table, [SumResult]>0),
    [SumResult]
)

 

it worked like:

FreemanZ_0-1677725909458.png

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.