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

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

Reply
Ken_Jorp
Frequent Visitor

Counting historical days in active status + days in active status today

Hi, 

I have created a calculated column that counts number of days a specific serial number has been in a specific status, "Redress". 

This works pretty good, but I have encountered a challenge: As the DAX only calculates days BETWEEN "Redress In" and Redress Out"  it will fail to count the days for the serial numbers which are in "Redress In" status today.

So what I need is a way to include a calculation in my current DAX, that counts the days since each serial went into "Redress In" status - Where there are no "Redress Out" after "Redress In"  for the specific serial number.

Here is my current DAX:

 

DAYS ON REDRESS COL =
VAR myindex = CALCULATE(MAX (_ITH_All2[Index]),_ITH_All2[Location Status]="Redress Out")

VAR myserial = _ITH_All2[SERIAL_NO]

 

VAR previousindex =
CALCULATE (
MAX ( _ITH_All2[Index] ),_ITH_All2[Location Status]="Redress In",
FILTER ( _ITH_All2,_ITH_All2[SERIAL_NO] = myserial
&& _ITH_All2[Index] < myindex)
)

 

VAR previousdate =
CALCULATE (
MAX ( _ITH_All2[Date Applied] ),
FILTER (
_ITH_All2,
_ITH_All2[Index] = previousindex
&& _ITH_All2[SERIAL_NO] = myserial
)
)

 

RETURN
IF ( previousdate , _ITH_All2[Date Applied] - previousdate)

 

Which gives me this data, but as you see, this serial number is currently in "Redress In" status, so I would like to count the days from "Redress in" to TODAY. 

Ken_Jorp_1-1614154286607.png

 

Thanks in advance.

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Ken_Jorp , Create these three measures and try

 

 

_date =
VAR __id = MAX ('Table'[ID] )
VAR __date = CALCULATE ( MAX('Table'[date applied] ), ALLSELECTED ('Table' ), 'Table'[ID] = __id )
CALCULATE ( Min ('Table'[status] ), VALUES ('Table'[ID] ),'Table'[ID] = __id,'Table'[date applied] = __date )

 

_status =
VAR __id = MAX ('Table'[ID] )
VAR __date = CALCULATE ( MAX('Table'[date applied] ), ALLSELECTED ('Table' ), 'Table'[ID] = __id )
CALCULATE ( Min ('Table'[date applied] ), VALUES ('Table'[ID] ),'Table'[ID] = __id,'Table'[date applied] = __date )

 

 

diff = if([Status] ="Redress In", datediff(_date, today(), day), blank())

 

 

diff = sumx(values(Table[ID]),if([Status] ="Redress In", datediff(_date, today(), day), blank()))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Ken_Jorp , Create these three measures and try

 

 

_date =
VAR __id = MAX ('Table'[ID] )
VAR __date = CALCULATE ( MAX('Table'[date applied] ), ALLSELECTED ('Table' ), 'Table'[ID] = __id )
CALCULATE ( Min ('Table'[status] ), VALUES ('Table'[ID] ),'Table'[ID] = __id,'Table'[date applied] = __date )

 

_status =
VAR __id = MAX ('Table'[ID] )
VAR __date = CALCULATE ( MAX('Table'[date applied] ), ALLSELECTED ('Table' ), 'Table'[ID] = __id )
CALCULATE ( Min ('Table'[date applied] ), VALUES ('Table'[ID] ),'Table'[ID] = __id,'Table'[date applied] = __date )

 

 

diff = if([Status] ="Redress In", datediff(_date, today(), day), blank())

 

 

diff = sumx(values(Table[ID]),if([Status] ="Redress In", datediff(_date, today(), day), blank()))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

@amitchandak Thanks! That certainly did the trick:)

Helpful resources

Announcements
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.