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
Cobra77
Post Patron
Post Patron

Calculate Monthly Lost Working Days

Hi,

 

I want calculate Monthly Lost Working Days.

Sample Data ;

lostdays_data.jpg

it's just a small data set, in reality , we have millions of lines in fact table '90 - Accidents'

 

DateAccident is connected with '01 - Calendar'

'Calendar' is connected with nothing

We have a slicer on '01 - Calendar'[Dates] to filter the pbix report.

 

Measure :

Nb lostdays :=
VAR AllPossibleDates = GENERATE('90 - Accidents';'Calendar')
VAR FlagDates = FILTER(ADDCOLUMNS(AllPossibleDates;"Flag";IF('Calendar'[Date]>IF(ISBLANK('90 - Accidents'[lostTimeStartDate]);NOW();'90 - Accidents'[lostTimeStartDate] ) && 'Calendar'[Date]<=IF(ISBLANK('90 - Accidents'[lostTimeEndDate]);NOW();'90 - Accidents'[lostTimeEndDate]);1;0));[Flag]=1)
RETURN
SUMX(FlagDates;[Flag])

 

and the graphic :

lostdays.jpg

 

but the result its false. ( Axe : Calendar table )

 

How filter only on july (in this example) like the slicer , or limit on the year ( year max of slicer) ? ,  and how to remove the date filter in the calculation, if I have accidents before July and they end during or after.

 

Thanks for your helps

2 REPLIES 2
v-cherch-msft
Employee
Employee

Hi @Cobra77

 

You may try to use below measure. Here is the sample file for your reference. Please let me know if that makes sense.

Nb lostdays =
VAR a =
    FILTER (
        GENERATE ( 'Calendar', '90 - Accidents' ),
        '90 - Accidents'[lostTimeStartDate] <= 'Calendar'[Date]
            && '90 - Accidents'[lostTimeEndDate] >= 'Calendar'[Date]
    )
RETURN
    COUNTROWS ( a ) + 0

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

hi @v-cherch-msft

 

thanks for your test and file,

 

but the good result for july its 67 lots days , not only 5

miss people1 and 2 , not present in july

 

and your calendar its only 2018 , we have 2010 to 2018.

we must limit the calendar dynamically follow the slicer.

 

Thanks if you find.

 

 

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.