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
DTN721
Regular Visitor

Filtered Distinct Count with CALCULATE not working as intended

Hi,

 

I have one table named Query1 in my Power BI report which has about 4 million rows of data and it looks a bit like this:

CustomerIDLogin DateCountryLevelHighest Level
ABC10/10/2021UK12
ABC10/10/2021UK12
ABC10/10/2021UK12
ABC11/10/2021UK22
ABC12/10/2021UK22
DEF10/10/2021France13
DEF11/10/2021France23
DEF11/10/2021France23
DEF12/10/2021France33
GHI12/10/2021UK13
GHI12/10/2021UK13
GHI12/10/2021UK13
GHI15/10/2021UK13
GHI17/10/2021UK23
GHI19/10/2021UK33

 

I want to write 3 DAX measures to count the distinct number of Login dates for each customer to find out how many days they have spent on each level.

 

So that the desirable outcome when using the measures for a table would look something like this:

 Total Days Spent on Level 1

Total Days Spent on Level 2

Total Days Spent on Level 3
ABC120
DEF111
GHI212

 

I've tried this to calculate the desirable measures:

Days Spent on L1 = CALCULATE( DISTINCTCOUNT (Query1[Login Date] ), Level = "1" ) 

Days Spent on L2 = CALCULATE( DISTINCTCOUNT (Query1[Login Date] ), Level = "2" ) 

Days Spent on L3 = CALCULATE( DISTINCTCOUNT (Query1[Login Date] ), Level = "3" ) 

 

However, rather than doing a DISTINCTCOUNT on the Login Dates, it's counting all the duplicate Login Dates and the table looks like this:

 Total Days Spent on Level 1

Total Days Spent on Level 2

Total Days Spent on Level 3
ABC320
DEF121
GHI411

 

Any help on this is very much appreciated it. Thanks in advance! 🙂

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@DTN721 , Please check date does not have any timestamp. Change datatype to datetime and choose a format with time and check. If there is a timestamp, then create date only column

 


Date = [datetime].date
or
Date = date(year([datetime]),month([datetime]),day([datetime]))

 

 

also, try with filter

Days Spent on L1 = CALCULATE( DISTINCTCOUNT (Query1[Login Date] ), filter( Query1, Query[ Level] = "1" ))

Days Spent on L2 = CALCULATE( DISTINCTCOUNT (Query1[Login Date] ), filter( Query1, Query[ Level] = "2" ))

Days Spent on L3 = CALCULATE( DISTINCTCOUNT (Query1[Login Date] ), filter( Query1, Query[ Level] = "3" ))

View solution in original post

3 REPLIES 3
DTN721
Regular Visitor

@Fsciencetech  @amitchandak  Thank you both so much for your time! Your suggestions worked 😊

Fsciencetech
Helper III
Helper III

@DTN721 

Noting issue in your measure, but first check your Logindate column, Is this is date datatype?, and also remove timestamp.

amitchandak
Super User
Super User

@DTN721 , Please check date does not have any timestamp. Change datatype to datetime and choose a format with time and check. If there is a timestamp, then create date only column

 


Date = [datetime].date
or
Date = date(year([datetime]),month([datetime]),day([datetime]))

 

 

also, try with filter

Days Spent on L1 = CALCULATE( DISTINCTCOUNT (Query1[Login Date] ), filter( Query1, Query[ Level] = "1" ))

Days Spent on L2 = CALCULATE( DISTINCTCOUNT (Query1[Login Date] ), filter( Query1, Query[ Level] = "2" ))

Days Spent on L3 = CALCULATE( DISTINCTCOUNT (Query1[Login Date] ), filter( Query1, Query[ Level] = "3" ))

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.