Forum Discussion
undefined
hi AditiGupta_
If you just need the specific entities to display 0 in a table or matrix when they lack input hours, a simple IF statement checking for blanks will do the job.
Prod Efficiency =
VAR _InputHours = [Input Hours]
VAR _OutputHours = [Output Hours]
RETURN
IF (
ISBLANK ( _InputHours ) || _InputHours == 0,
0, -- Forces a 0 if input hours are missing or exactly zero
DIVIDE ( _OutputHours, _InputHours, 0 )
)
While this fixes the individual entity rows, your Grand Total might still sum up the output of the "zeroed" entities and divide it by the total inputs, which isn't always mathematically accurate for efficiency.
Approach 2:
Because you mentioned selecting multiple entities at the same time, we need to ensure the Grand Total ignores the output hours of any entity that is missing its input hours. Otherwise, your total efficiency is inaccurate.
We can achieve this by using an iterator (FILTER and VALUES) to create a virtual table of only the valid entities before doing the math.
Prod Efficiency =
-- 1. Build a virtual table of entities in the current filter context that ACTUALLY have input hours
VAR _ValidEntities =
FILTER (
VALUES ( 'YourEntityTable'[EntityName] ),
NOT ISBLANK ( [Input Hours] ) && [Input Hours] > 0
)
-- 2. Calculate Output and Input strictly for those valid entities
VAR _ValidOutput =
CALCULATE ( [Output Hours], _ValidEntities )
VAR _ValidInput =
CALCULATE ( [Input Hours], _ValidEntities )
VAR _CurrentInput = [Input Hours]
RETURN
-- 3. If the current row has no input, return 0. Otherwise, safely divide the valid numbers.
IF (
ISBLANK ( _CurrentInput ) || _CurrentInput == 0,
0,
DIVIDE ( _ValidOutput, _ValidInput, 0 )
)
If this solves your problem, mark this as solution and give me a kudos