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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
JBarrett3
Frequent Visitor

Count instances where Aggregated Sum is zero

Hi all,

 

I have table like the below. I need to build a dynamic measure that will indicate if the total pump run hours per site for a given date is zero so that I can count or filter on sites with total zero hours. 

 

Source table:

SiteDatePumpRun_Hours
AAA01/01/201910
BBB01/01/201916
BBB01/01/201920
CCC01/01/201914
DDD01/01/201910
DDD01/01/201920

 

Desired output:

SiteDateZero_Hour_Sites
AAA01/01/20191
BBB01/01/20190
CCC01/01/20190
DDD01/01/20191
Total 2

 

I have found a similar requirement here where the proposed solution was something along the lines of:

 

Measure =
COUNTROWS (
DISTINCT ( CALCULATETABLE ( VALUES ( Table[Site] ), Table[Run Hours] = 0 ) )
)

 

But I am not sure how to enhance this to group by both Site and Date?

 

Many thanks.

 

Jeanette

1 ACCEPTED SOLUTION

@JBarrett3 Ok, please update the Measure logic as below

 

Test308 = 
VAR _Zero = DISTINCT(SELECTCOLUMNS(FILTER(Test308Filter,Test308Filter[Run_Hours]=0),"Site",[Site],"Date",[Date]))
VAR _NonZero = DISTINCT(SELECTCOLUMNS(FILTER(Test308Filter,Test308Filter[Run_Hours]>0),"Site",[Site],"Date",[Date]))
RETURN COUNTROWS(DISTINCT(EXCEPT(_Zero,_NonZero)))+0

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




View solution in original post

3 REPLIES 3
PattemManohar
Community Champion
Community Champion

@JBarrett3  Please try this as New Measure.

 

Test308 = COUNTROWS(DISTINCT(EXCEPT(CALCULATETABLE(VALUES(Test308Filter[Site]),Test308Filter[Run_Hours]=0),CALCULATETABLE(VALUES(Test308Filter[Site]),Test308Filter[Run_Hours]>0))))+0

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Thank you so much.

That works great for 1 day, but when I introduce a second date the total no longer works. Any idea how to resolve that?

 

image.png

image.png

@JBarrett3 Ok, please update the Measure logic as below

 

Test308 = 
VAR _Zero = DISTINCT(SELECTCOLUMNS(FILTER(Test308Filter,Test308Filter[Run_Hours]=0),"Site",[Site],"Date",[Date]))
VAR _NonZero = DISTINCT(SELECTCOLUMNS(FILTER(Test308Filter,Test308Filter[Run_Hours]>0),"Site",[Site],"Date",[Date]))
RETURN COUNTROWS(DISTINCT(EXCEPT(_Zero,_NonZero)))+0

image.png





Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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