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
tjtommtj
New Member

Calculating Difference of counts (on columns) by date

Hi, I have some data that is visits to a website which looks like this: 

 

Date VisitID
08/01/2016111366
09/01/2016373823
10/01/2016608594
11/01/2016111366
10/01/2016887988
13/01/2016255210
14/01/2016693369
10/01/2016928357
14/01/2016299080
09/01/2016693369

 

So the dates arn't summed and the uniqueID can be on multiple dates. What I need is to be able to calculate the difference in counts of the amount of people (by VisitID). In Excel its easy to get a pivot of the dates and the count of visit id (but not distinct count). I then need it to work out the day on day difference in visits. 

 

Essentially I need to recreate this: 

 

DateDistinctCountOfVisitIDDaybydayDifference%Diff
08/01/20161  
09/01/201621200%
10/01/201631150%
11/01/20161-233%
13/01/201610100%
14/01/201621200%

 

Any help would be appreciated.

1 ACCEPTED SOLUTION
Sean
Community Champion
Community Champion

@tjtommtjthese 2 Measures should do it...

MEASURE 1

DayByDayDifference = 
VAR CurrentDate = MIN ( 'Table'[Date ] )
VAR PreviousDate = CALCULATE ( MAX ( 'Table'[Date ] ), 'Table'[Date ] < CurrentDate )
RETURN
    DISTINCTCOUNT ( 'Table'[VisitID] )
        - CALCULATE ( DISTINCTCOUNT ( 'Table'[VisitID] ), 'Table'[Date ] = PreviousDate )

MEASURE 2

% Difference = 
VAR CurrentDate = MIN ( 'Table'[Date ] )
VAR PreviousDate = CALCULATE ( MAX ( 'Table'[Date ] ), 'Table'[Date ] < CurrentDate )
RETURN
    DIVIDE (
        DISTINCTCOUNT ( 'Table'[VisitID] ),
        CALCULATE ( DISTINCTCOUNT ( 'Table'[VisitID] ), 'Table'[Date ] = PreviousDate )
    )

And the results...

 

Results - 2017-06-09 - VAR.png

Hope this helps! Smiley Happy

Good Luck!

View solution in original post

1 REPLY 1
Sean
Community Champion
Community Champion

@tjtommtjthese 2 Measures should do it...

MEASURE 1

DayByDayDifference = 
VAR CurrentDate = MIN ( 'Table'[Date ] )
VAR PreviousDate = CALCULATE ( MAX ( 'Table'[Date ] ), 'Table'[Date ] < CurrentDate )
RETURN
    DISTINCTCOUNT ( 'Table'[VisitID] )
        - CALCULATE ( DISTINCTCOUNT ( 'Table'[VisitID] ), 'Table'[Date ] = PreviousDate )

MEASURE 2

% Difference = 
VAR CurrentDate = MIN ( 'Table'[Date ] )
VAR PreviousDate = CALCULATE ( MAX ( 'Table'[Date ] ), 'Table'[Date ] < CurrentDate )
RETURN
    DIVIDE (
        DISTINCTCOUNT ( 'Table'[VisitID] ),
        CALCULATE ( DISTINCTCOUNT ( 'Table'[VisitID] ), 'Table'[Date ] = PreviousDate )
    )

And the results...

 

Results - 2017-06-09 - VAR.png

Hope this helps! Smiley Happy

Good Luck!

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.