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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DAXHeadroom
Frequent Visitor

Distinct Count of Dates with Multiple Values

Greetings. 

Using the following table as an example, I am using two separate measures to make a Distinct Count of the Date column when the Hours column is = 0 (Measure 1) and when the Hours column > 0 (Measure 2). These two measures are subtotals and need to be displayed independently. However, I am overstating the total count by one because November 12 has values that are both = 0 and > 0. A given date should only be counted once. How can I ensure the output counts November 12 only once in these instances? 

 

Current output for Measure 1 = 2

Current output for Measure 2 = 3

Total = 5

 

Desired output for Measure 1 = 1

Desired output for Measure 2 = 3

Total = 4

 

IDDateHours
63813-1Monday, November 11, 20191.7
63813-2Tuesday, November 12, 20190
63813-3Tuesday, November 12, 20191.2
63813-4Tuesday, November 12, 20192.1
63935-1Sunday, November 17, 20191.9
63935-2Sunday, November 17, 20191.8
63935-3Sunday, November 17, 20191.4
63935-4Monday, November 18, 20190

 

Many thanks for the assistance. 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@DAXHeadroom , Try measures like

 

countx(filter(summarize(Table, Table[Date], "_1", sum(Table[Hours])),[_1]>0),[Date])

or

countx(filter(summarize(Table, Table[Date], "_1", sum(Table[Hours])),[_1]=0),[Date])

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@DAXHeadroom , Try measures like

 

countx(filter(summarize(Table, Table[Date], "_1", sum(Table[Hours])),[_1]>0),[Date])

or

countx(filter(summarize(Table, Table[Date], "_1", sum(Table[Hours])),[_1]=0),[Date])

Hello @amitchandak

 

Your solution above worked well - thank you! Now, I am having a similar problem when making additional DISTINCTCOUNTS of other columns. Specifically, I am employing the following two Measures to the below sample data table.

 

Flight Days Away = CALCULATE(DISTINCTCOUNT('Appended Metrics'[Dept Date Local]),'Appended Metrics'[Leg Hours]>0,'Appended Metrics'[Ver]="-V-",'Appended Metrics'[Local SAV Flights]=0)

Non-Flight Days Away = CALCULATE(COUNTAX(FILTER(SUMMARIZE('Appended Metrics', 'Appended Metrics'[Dept Date Local], "_1", SUM('Appended Metrics'[Leg Hours])),[_1]=0),[Dept Date Local]),'Appended Metrics'[Ver]="-V-", 'Appended Metrics'[Dept AP]<>"KSAV",'Appended Metrics'[Arrive AP]<>"KSAV")

 
Dept Date Local Dept AP Arrv AP Leg Hours Ver
9/21/2020 KSAV KMMU 1.6 -V-
9/21/2020 KMMU KMMU 0 -V-
9/22/2020 KMMU KMMU 0 -V-
9/22/2020 KMMU KHPN 0.3 -V-
9/23/2020 KHPN KHPN 0 -V-
9/23/2020 KHPN KSAV 1.8 -V-


My output is:

Flight Days Away = 3

Non-Flight Days Away = 2*

 

Since any given day should be counted once, and Flight Days take precedence,  

my desired output is:

Flight Days Away = 3

Non-Flight Days Away = 0

 

*I'm also confused as to why this is 2 versus 3. Seems odd to me. 

 

Any help woudl be very much appreciated. 

 

Regards,

 

@DAXHeadroom

AlB
Super User
Super User

Hi @DAXHeadroom 

Measure 1 = 
COUNTROWS( FILTER(DISTINCT(Table1[Date]), CALCULATE(SUM(Table1[Hours])) = 0))

 

Measure 2 = 
COUNTROWS( FILTER(DISTINCT(Table1[Date]), CALCULATE(SUM(Table1[Hours])) > 0))

 

Please mark the question solved when done and consider giving a thumbs up if posts are helpful.

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

Cheers 

SU18_powerbi_badge

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors