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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Calculate/Visualize Time Duration Dynamically Based on Selected Values in Date Slicer / Row Context

Dear PBI Community Members,

I have a data file about children in child care service: the table has service begin date ('entry_date') and service end date ('exit_date') for each child, or censoring date (the last date of study period) for those still in service at end of fiscal year. I plan to visualize the length of service days for each child. I can caluclate the length of stay ('Los') by using the difference between (exit_date-entry_date). I have categorized the Los into a categorical field with several categories (a one week, b 9 days to 1 mont, c 1 to 3 months, etc.). I have generated the following visuals, showing the 'Los' categories for children who entered care during each month of FY2023 or in care service at end of each month. The month year period is from a calendar table, which is connected with 'entry_date' in the service table. The number of children entering care and in care are the two measures that I created from the date and care tables.    IN the 1st matrix table visual (children entries), the Los categorical field is used as the column field. In the 2nd visual (children in care), the Los field is used as the legend. 

As you can see, the Los field is calculated as the length until the exit date. I would like to calculate a new Los field 'los_new', which is is the length of stay until the (begining or end of) current date period selected. That is Los_new=current date selected-entry_date. 

I would also like to create a categorical field based on 'Los_new' and used it as a table column or legend in the bar chart.  

Is there any way I cab achieve this using Power BI? Any suggestions/advice are appriciated.     

Thanks.    

 

LijunChen_0-1710450676112.png

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , for that you need a measure like

 

Sumx(Table,datediff( Max(selectedvalue(Date[Date]) , Table[Start Date]), Min(selectedvalue(Date[Date]) , Table[Exit Date]), Day))

 

As this a measure, you need segmentation for frequency

 

example

Dynamic segmentation -Measure to Dimension conversion: https://youtu.be/gzY40NWJpWQ

 

Also joins with the date table can be active or inactive based on the need, refer files if needed

 

 

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

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , for that you need a measure like

 

Sumx(Table,datediff( Max(selectedvalue(Date[Date]) , Table[Start Date]), Min(selectedvalue(Date[Date]) , Table[Exit Date]), Day))

 

As this a measure, you need segmentation for frequency

 

example

Dynamic segmentation -Measure to Dimension conversion: https://youtu.be/gzY40NWJpWQ

 

Also joins with the date table can be active or inactive based on the need, refer files if needed

 

 

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.