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

Preparing for a certification exam? Ask exam experts all your questions on May 15th. Register now.

Reply
Anonymous
Not applicable

Arithmetic from diff periods of time off of the same table

 

Dear Community,

 

during any given time I'm trying to create a measure that will help me count the actives of N Days Ago

for example, during 3rd of Jan if I want to count of actives 2 days ago it would be 8.

 

and 4-Jan (current)(8) minus 1-Jan (2 days)(6) ago would be =  8 (Active Occurances) - 6 (Active Occurances) = 5

 

DateActive
1-Jan 
1-Jan 
1-Jan 
1-Jan 
1-Jan 
1-JanActive
1-JanActive
1-JanActive
1-JanActive
1-JanActive
1-JanActive
1-JanActive
1-JanActive
2-JanActive
2-JanActive
2-JanActive
2-JanActive
2-JanActive
2-JanActive
2-JanActive
2-JanActive
2-JanActive
3-JanActive
3-JanActive
3-JanActive
3-Jan 
3-Jan 
3-Jan 
3-Jan 
3-Jan 
3-Jan 
3-Jan 
3-Jan 
3-Jan 
3-Jan 
4-Jan 
4-Jan 
4-JanActive
4-JanActive
4-JanActive
4-JanActive
4-JanActive
4-JanActive
5-JanActive
5-JanActive
5-JanActive
5-JanActive
5-JanActive
5-JanActive
5-JanActive
5-Jan 
5-Jan 
5-Jan 
5-Jan 
5-Jan 
5-Jan 
5-Jan 
5-Jan 
5-Jan 

 

I'm using days as an example but what I really want is to go back months behind.

So Far I've tried a simple Date Count.

 

 

 

Count_Measure = CALCULATE(COUNT(Table[Date]),LASTDATE(date(year(Table[Date]),MONTH(Table[Date]),DAY(Table[Date])-2)))

 

 

 it didn't work

thanks in advance

 

1 ACCEPTED SOLUTION

Hi @Anonymous 

I think you can build two slicer to select the date you need in your measure.

Build two calculated tables to create slicer.

Current Date = VALUES('Table'[Date])
Previous Date = VALUES('Table'[Date])

Measure:

Difference =
VAR _Previous =
    SELECTEDVALUE ( 'Previous Date'[Date] )
VAR _Current =
    SELECTEDVALUE ( 'Current Date'[Date] )
VAR _CountPreviousActive =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        'Table'[Date] = _Previous,
        'Table'[Active] = "Active"
    )
VAR _CountCurrentActive =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        'Table'[Date] = _Current,
        'Table'[Active] = "Active"
    )
RETURN
    ABS ( _CountCurrentActive - _CountPreviousActive )

Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

@Anonymous Seems like if you have a date range slicer you could do something like this:

Measure =
  VAR __MaxDate = MAX('Date'[Date])
  VAR __MinDate = MIN('Date'[Date])
RETURN
  COUNTROWS(FILTER('Table',[Date]<=__MaxDate && [Date] >=__MinDate && [Active]="Active"))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

thank you for your quick reply,

 

im not after a range, im trying to compare between two individual dates

@Anonymous Whether a date range slicer or not, the same logic applies. Get a date somehow. Use simple math like [Date] - 30 or a whole host other other ways to caclulate your other date. Might help if I understood what you actually wanted as output because the example you provided doesn't make any sense 8 - 3 = 5, I have no idea where you are getting those numbers from the sample data provided.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Correction: it would be 8-6

 

number of actives in 4th of jan minus number of actives in 1st of jan

 

I'm imagining something like this 

Calculate(Count(Date[Date]), Date[Date] = Date[Date] - 3)

But obviously, this didn't work

Hi @Anonymous 

I think you can build two slicer to select the date you need in your measure.

Build two calculated tables to create slicer.

Current Date = VALUES('Table'[Date])
Previous Date = VALUES('Table'[Date])

Measure:

Difference =
VAR _Previous =
    SELECTEDVALUE ( 'Previous Date'[Date] )
VAR _Current =
    SELECTEDVALUE ( 'Current Date'[Date] )
VAR _CountPreviousActive =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        'Table'[Date] = _Previous,
        'Table'[Active] = "Active"
    )
VAR _CountCurrentActive =
    CALCULATE (
        COUNTROWS ( 'Table' ),
        'Table'[Date] = _Current,
        'Table'[Active] = "Active"
    )
RETURN
    ABS ( _CountCurrentActive - _CountPreviousActive )

Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
PBIApril_Carousel

Power BI Monthly Update - April 2025

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

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

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