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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Guillermox
Regular Visitor

Calculate Lab days between the last date and the previous date

Hello, I want to calculate the business days between the record date of the last date by type and the previous type date in a measure that I will place in a matrix visualization filtered by teams in rows and in columns by Type. (additionally I am calculating an average of % but could not calculate the days)

 

Table   
Team#Type%ResultDate
AT180%4/03/2022
AT281%9/03/2022
AT379%17/03/2022
YT178%19/03/2022
YT285%20/03/2022
AT485%6/04/2022
AT586%15/04/2022
AT687%22/04/2022
ZT285%1/04/2022
ZT385%6/04/2022
YT386%25/03/2022
YT485%26/03/2022
ZT186%25/03/2022
ZT475%13/04/2022
ZT586%18/04/2022

 

In a table matrix visualization, I added the measure by type so that I got something like this:

Visualization table (messure) 
        
TeamT1T2T3T4T5T6 
A 471586#Days
Y 051  #Days
Z 6464 #Days

 

Guillermox_0-1687818415989.png

 

How can you calculate the days? because also later validate that a certain number of days have not passed between each type.

1 ACCEPTED SOLUTION

maybe you can try this

Measure = 
VAR _c=max('Table'[Date])
VAR _l=maxx(FILTER(all('Table'),'Table'[Team]=max('Table'[Team])&&'Table'[Date]<max('Table'[Date])),'Table'[Date])
return if(ISBLANK(_c)||ISBLANK(_l),BLANK(),NETWORKDAYS(_l,_c))

1.PNG

pls see the attachment below

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

6 REPLIES 6
LukeVanLaar26
Regular Visitor

I would create a "Types" dimension table with an index:

LukeVanLaar26_1-1687827575581.png

 

Relate that to your fact table:

LukeVanLaar26_2-1687827716801.png

 

Then write the following measure:

Cycle Time (Workdays) = 
VAR _SelectedType = SELECTEDVALUE('Table'[#Type])
VAR _SelectedTypeIndex = LOOKUPVALUE(Types[Index],Types[Type],_SelectedType)
VAR _PreviousTypeIndex = _SelectedTypeIndex - 1
VAR _FirstDate = LASTDATE('Table'[Date])
VAR _SecondDate = CALCULATE(LASTDATE('Table'[Date]),ALL('Table'[#Type]),Types[Index] = _PreviousTypeIndex)
VAR _Result = NETWORKDAYS(_FirstDate,_SecondDate)
RETURN
IF(ISBLANK(_SecondDate),0,_Result)

 

Put that on your matrix:

LukeVanLaar26_4-1687828221327.png

 

Hope that works for you!

 

Connect on LinkedIn

 

ryan_mayu
Super User
Super User

@Guillermox 

could you pls explain the calculation logic?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hello @ryan_mayu , I need to calculate the number of days from the most recent record date vs the previous record date segmented by the "Type" column. Example: Date T7 - Date T6, Date T6 - Date T5 ...Date T2 - Date T1. But accept the context filters and external filters since my table has many more columns like teams, sub team, dimension, and external filters like Roles, Period, etc.
To then show the user a matrix table where I place the team, sub team, %, Type Date, and the days between each registration date.
In my image I want to add that column in my matrix table showing the calculated measure.

Thanks.

maybe you can try this

Measure = 
VAR _c=max('Table'[Date])
VAR _l=maxx(FILTER(all('Table'),'Table'[Team]=max('Table'[Team])&&'Table'[Date]<max('Table'[Date])),'Table'[Date])
return if(ISBLANK(_c)||ISBLANK(_l),BLANK(),NETWORKDAYS(_l,_c))

1.PNG

pls see the attachment below

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thank you very much, this worked best for me.

you are welcome





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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