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
Ken_Jorp
Frequent Visitor

Display active dates based on date diff

Hi, I have two existing queries that counts historical days between redress in and redress out (active days) - and one that counts days if on active redress today.

My problem is that my existing queries sums the active days, and place the result on each redress out date. This creates a challenge for me when adding this measure to a date chart to display e.g average active days per month. As you see in the snip below, the item have been active in 35 days, but the result is only showing in July, whilst I need it to display sum of active days for June and July.

Also, for the last measure, that counts days on redress now, it shows 137 days in October, but should be showing all active days the last months.

Ken_Jorp_0-1614582448169.png

 

Here's my column and measures as is now:

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)
 
 Measures:
_Status =
VAR __id = MAX (_ITH_All2[SERIAL_NO] )
VAR __date = CALCULATE ( MAX(_ITH_All2[Date Applied] ), ALLSELECTED ('_ITH_All2' ), _ITH_All2[SERIAL_NO] = __id )
RETURN
CALCULATE ( Min (_ITH_All2[Location Status] ), VALUES ('_ITH_All2'[SERIAL_NO] ),'_ITH_All2'[SERIAL_NO] = __id,_ITH_All2[Date Applied]= __date )
last_date =
VAR __id = MAX (_ITH_All2[SERIAL_NO] )
VAR __date = CALCULATE ( MAX(_ITH_All2[Date Applied] ), ALLSELECTED ('_ITH_All2' ), _ITH_All2[SERIAL_NO] = __id )
RETURN
CALCULATE ( Min (_ITH_All2[Date Applied] ), VALUES (_ITH_All2[SERIAL_NO] ),_ITH_All2[SERIAL_NO] = __id,_ITH_All2[Date Applied] = __date )
Days On Redress now = sumx(values(_ITH_All2[SERIAL_NO]),if([_Status] ="Redress In", datediff([last_date], today(), day), blank()))
Days on redress historical= Sum(DAYS ON REDRESS COL)
 
Days on Redress All= Days on redress historical + Days On Redress now
 
So, a measure to display sum of active days for each period, and a measure to display average days per period would be highly appreciated. 
Thanks in advance!
0 REPLIES 0

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.

Top Solution Authors