Forum Discussion
Dynamic Days calculation from 2 dates
- 3 years ago
Hi Anonymous ,
According to your description, I created a sample, and here is my solution.
To get the expected output 1, DATEDIFF function does help.
Create a column:
No of days of WFH applied for the week = IF ( COUNTROWS ( FILTER ( 'Table 1', 'Table 1'[Employee Number] = EARLIER ( 'Table 1'[Employee Number] ) && 'Table 1'[To Date] <= DATE ( 2022, 8, 26 ) && 'Table 1'[From date ] >= DATE ( 2022, 8, 22 ) ) ) > 0, DATEDIFF ( 'Table 1'[From date ], 'Table 1'[To Date], DAY ) + 1, IF ( COUNTROWS ( FILTER ( 'Table 1', 'Table 1'[Employee Number] = EARLIER ( 'Table 1'[Employee Number] ) && 'Table 1'[To Date] > DATE ( 2022, 8, 26 ) && 'Table 1'[From date ] >= DATE ( 2022, 8, 22 ) ) ) > 0, DATEDIFF ( 'Table 1'[From date ], DATE ( 2022, 8, 26 ), DAY ) + 1 ) )Final Output:
To get the expected output 2, please use Power Query to create a custom column. And then expand to new rows, you will get the expected result.
Final output:
I attach my sample below for your reference.
Best Regards,
Community Support Team _ xiaosunIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous going to need to create a CALENDAR table in a VAR between the 2 dates. Use ADDCOLUMNS to add a WEEKNUM. Strikes me as similar to these:
Take a look at these two Quick Measures as I think you want something like them.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364
https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365