cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Anonymous
Not applicable

Getting a Percentage Measure to Show 0% for True 0s

I'm trying to create a measure that tracks whether an event was completed on time.  For each event, I have an event completion date and an event due date in my data.  If an event's completion date is <= the due date, that event is considered to have been completed on time.  If the completion date is > the due date, that event did not complete on time.  If an event has no completion date, I do not want this measure to calculate since it's not applicable.  

 

In my data, I have an [Events_Completed] field that returns a 1 if the event's completion date is populated.  I also have an [Events_Completed_On_Time] field that returns a 1 if the event has a completion date, a due date, and the completion date is <= the due date; it returns a 0 if the event has a completion date, a due date, and the completion date is > the due date; and it returns nulls if the completion date and due date are not populated.  

 

In AAS, I have an [Events Completed] measure that is calculated as SUM ( 'Events'[Events_Completed] ), and I have an [Events Completed On Time] measure that is calculated as SUM ( 'Events'[Events_Completed_On_Time]).  Finally, my [Events Completed On Time %] measure is DIVIDE ( [Events Completed On Time], [Events Completed] ).  

 

When I view the percentage measure at a high level, everything looks good.  When I go down to the level of the individual event, however, my client wants to see 100% if an event completed on time, 0% if an event did not complete on time, and a blank if the event has not completed.  The problem is that the events that have a 0 for [Events_Completed_On_Time] and a 1 for [Events_Completed] in my data are returning as blanks when placed in a visual when I expect to see 0% instead.  

 

I know that this is a quirk of Power BI, but I haven't been able to correct this with any of the usual tricks.  I can't just do DIVIDE ( [Events Completed On Time], [Events Completed] ) + 0 because that will give me 0% for everything, even if an event hasn't completed.  I've also tried IF ( NOT ( ISBLANK ( [Events Completed On Time] ) ), DIVIDE ( [Events Completed On Time], [Events Completed] ) + 0 ), but that still returns either 100% or blanks.  

 

Is there some way I can alter this calculation so that I see 100% if an event was completed on time, a 0% if the event completed and was not on time, and a blank if the event has not yet completed?  

2 REPLIES 2
ukare1996
Helper I
Helper I

did you manage to figure this out? I am having the same issue?

Anonymous
Not applicable

EventCompleted = 
VAR comletedEvents = IF(max(Event[CompletionDate])<>BLANK(),1,0)
var ontimecompletedEvents = IF(AND(MAX(Event[CompletionDate])<=MAX(Event[DueDate]),comletedEvents=1),1,0)
RETURN IF(comletedEvents=1,DIVIDE(comletedEvents,ontimecompletedEvents,0))

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors