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
Anonymous
Not applicable

IF Statement for a column not working

Hi, I am currently trying to create a column with an IF statement that returns back a 1 if true or 0 if false.

The table shows every time a user has taken a sick day in their period of working and each time is registered as a separate event, so for example, if someone called in sick for 2 days in a row, it still shows as two separate events. Also, this means the User ID comes up multiple times.

 

What the filter needs to do is to figure out whether a user has had 9 or more absences in a 4 month period, and if they have then for their ID mak down as 1 (true), if not then 0 (false).

There is a separate column for User ID, their start date, their end date, and a sick column then marks down as 1 or 0.5 per sickness leave.

It might be better to add up the sick days first in a column but I was not sure because it only matter if it is 9 or more absences in 4 months.

I've tried a lot of methods but I am not familiar with DAX yet and am unsure.

Would someone be able to help please?

 

Below is what I was working opn but it does not work:

 

if(([SicknessDays]>8), (datediff([StartDate], [EndDate], [60])), true(), false())

1 ACCEPTED SOLUTION
tackytechtom
Super User
Super User

Hi @Anonymous ,

 

Thanks for the data! I think I got to a solution:

tomfox_0-1645467706711.png

 

I did it in two steps but both steps are already incorporated in the measure below. First, I created the column TomsRolling4Column which returns the 4 month window for each User ID (see picture above) This equals everything in the FILTER statement below (in green). Afterwards, we only need to distinct count all User IDs which have a number >= 9 in the new column (blue below). 

 

TomsRolling4Measure = 
CALCULATE ( 
    DISTINCTCOUNT ( Table[User ID] ),
    FILTER (
        Table,
        CALCULATE (
            SUM (Table[Sickness Amount (Days)] ),
            ALLEXCEPT ( Table, Table[User ID] ),
            DATESINPERIOD(
                Table[Sickness Date],
                Table[Sickness Date],
                -4, MONTH
            )
        ) >= 9 
    )
)

 

Please try it and let me know if it works 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

View solution in original post

3 REPLIES 3
tackytechtom
Super User
Super User

Hi @Anonymous ,

 

Thanks for the data! I think I got to a solution:

tomfox_0-1645467706711.png

 

I did it in two steps but both steps are already incorporated in the measure below. First, I created the column TomsRolling4Column which returns the 4 month window for each User ID (see picture above) This equals everything in the FILTER statement below (in green). Afterwards, we only need to distinct count all User IDs which have a number >= 9 in the new column (blue below). 

 

TomsRolling4Measure = 
CALCULATE ( 
    DISTINCTCOUNT ( Table[User ID] ),
    FILTER (
        Table,
        CALCULATE (
            SUM (Table[Sickness Amount (Days)] ),
            ALLEXCEPT ( Table, Table[User ID] ),
            DATESINPERIOD(
                Table[Sickness Date],
                Table[Sickness Date],
                -4, MONTH
            )
        ) >= 9 
    )
)

 

Please try it and let me know if it works 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

tackytechtom
Super User
Super User

Hi @Anonymous ,

 

Knowing that this is some pretty sensitive data you are working with, do you still think you could provide some anonymized / mockup sample data as well as the outcome you'd like to achieve? 

 

Thanks!

 

/Tom

https://www.tackytech.blog

https://www.instagram.com/tackytechtom



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

Anonymous
Not applicable

 

Hi @tackytechtom ,

 

Thank you. Below I have aded a mockup of the data. The last column is the Count which returns a 1 (True) if someone has had 9 absences or more in a 4 month period. I am unsure if this is the best way to do it because all I need to do is have a Count on the Report that shows how many Users have had 9 or more absences in a 4 month period. I then need a way to reset that count live.

 

User 189 has had 12 absences but only 10 are in a 4 month period of each other so those have a Count of 1 but the other two do not. Also, the Sickness Amount has to add up to 9 or more bearing in mind that some have a count of 0.5 for half days.

 

Thank you,

 

Chezz

 

 

User IDWork Start DateWork End DateSickness DateSickness Amount (Days)Count
12202/02/201505/10/201611/12/20151.00
12202/02/201505/10/201612/12/20151.00
12202/02/201505/10/201613/12/20151.00
12202/02/201505/10/201603/09/20160.50
21401/01/201804/06/201809/05/20181.00
21401/01/201804/06/201802/06/20181.00
18903/05/201914/12/202103/01/20201.01
18903/05/201914/12/202104/01/20201.01
18903/05/201914/12/202105/01/20201.01
18903/05/201914/12/202106/01/20201.01
18903/05/201914/12/202107/01/20201.01
18903/05/201914/12/202117/02/20201.01
18903/05/201914/12/202118/02/20201.01
18903/05/201914/12/202119/02/20201.01
18903/05/201914/12/202101/03/20201.01
18903/05/201914/12/202102/03/20201.01
18903/05/201914/12/202114/11/20211.00
18903/05/201914/12/202115/11/20210.50

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.