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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
Anonymous
Not applicable

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
Community Champion
Community Champion

@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!:
DAX For Humans

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!:
DAX For Humans

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

Anonymous
Not applicable

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors