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
ddeutschman
Helper I
Helper I

How calculate a column based on

I need to calculate the Number of days since either

 

1.  Start of a Job

2.  Since the last Type of Event

 

There is a relationship between the Job Table and Event table.  There may be  multiple Events for a job for there may be none.  If there are no events, then I want to set the date of the last event to the Date the Job started otherwise set the Date to the most recent Event Date.  The following dows not work as it gives me the Earliest date for All events. 

 

Date Last Recordable = IF (MIN('UMC Safety Incident Log'[Date of Incident]) < udJob[StartDate], udJob[StartDate], MIN('UMC Safety Incident Log'[Date of Incident]))

 

What is the correct syntax for the formla?

9 REPLIES 9
v-ljerr-msft
Employee
Employee

Hi @ddeutschman,

 

Could you try the formula below to see if it works in your scenario? Smiley Happy

Date Last Recordable =
IF (
    ISBLANK ( CALCULATE ( MIN ( 'UMC Safety Incident Log'[Date of Incident] ) ) ),
    udJob[StartDate],
    CALCULATE ( MIN ( 'UMC Safety Incident Log'[Date of Incident] ) )
)

 

Regards

Sorry, I have been out of the office and unable to test the function.

 

That worked but I realized that I need to base the calculation on another column, UMC Status in UMC Safety Incident Log.  I tried the following but get the error that a single value for the column UMC Status can not be determined. 

 

Date Last Recordable = IF ('UMC Safety Incident Log'[UMC Status] = "Recordable", IF(ISBLANK ( CALCULATE ( MIN ( 'UMC Safety Incident Log'[Date of Incident] ) ) ), udJob[StartDate], CALCULATE ( MIN ( 'UMC Safety Incident Log'[Date of Incident] ) ) ))

 

Thanks in advance for your assistance.  I am a newbie and am still learning how to build formulas.

Can I use the Related function to only return the rows in UMC Safety Incident Log where the column UMC Status = "Recordable" in the formula?  There is a direct relationship between the udJob and UMC Safety Incident Log tables.  If so, how would that look?

Hi @ddeutschman,

 

Could you try the formula below to see if it works in your new scenario? Smiley Happy

Date Last Recordable =
IF (
    CALCULATE ( FIRSTNONBLANK ( 'UMC Safety Incident Log'[UMC Status], 1 ) )
        = "Recordable",
    IF (
        ISBLANK ( CALCULATE ( MIN ( 'UMC Safety Incident Log'[Date of Incident] ) ) ),
        udJob[StartDate],
        CALCULATE ( MIN ( 'UMC Safety Incident Log'[Date of Incident] ) )
    )
)

Regards

No.  It did not return the the last Recordable Date for all Jobs.   It did for only one - 6881.  The FIRSTNONBLANK function is not finding the last entry in the data set.

 

I have an excel file with a subset of the jobs so you can see an example of the data that is in the UMC Safety Incident Log table.   How can I upload the file?

Here is an example of the data:

 

UMC StatusDate of IncidentProject Number
 10/26/146262
UMC First Aid01/21/156262
Recordable01/27/156262
UMC First Aid06/18/156262
UMC First Aid09/03/156262
 10/08/156262
Recordable01/14/156265
Recordable07/19/166623
Notification08/09/166623
Notification10/03/166623
Notification10/07/166623
 12/01/166623
Notification05/15/176623
Recordable06/16/176623
UMC First Aid06/29/176623
UMC First Aid03/02/176881
Recordable04/21/176881
UMC First Aid05/10/176881
UMC First Aid06/08/177000

Hi @ddeutschman,

 

What result are you expecting on the pasted dataset?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Here are the expected results.

 

1.  Job 6262 has been closed.  I am filtering on Open jobs only in the table udJob.   So there isn't a row in udJob for it.

2.  Same is true for Job 6265.  It is closed so no row is found in udJob.

3.  For Job 6623, there are two events in the table UMC Safety Incident Log where the column UMC Status = Recordable.  The value to use for the custom column Last Recordable Date in the table udJob is the latest Date of Incident (Max) 2017-06-16

4.  For job 6881, there is one event in the table UMC Safety Incident Log where the column UMC Status = Recordable.  The value to use for the custom column Last Recordable Date in udJob is the Date of Incident: 2017-04-21

5.  For job 7000, there isn't an event where the column UMC Status = Recordable.  So the date to use for the custom column Date Last Recordable in the table udJob is the column StartDate from the table udJob.  That date is 2017-01-23

 

If there are no entries in the table UMC Safety Incident Log at all for a Job, then the result would be the same as example 5, the date used is the column StartDate from the table udJob.

Any further ideas?  If you could help me with the syntax for a function for determining the set of UMC Safety Incident Log rows that are related to the udJob row that is being evaluated, I think I could take it from there.  If there was a "Recordable" event, I am setting a Custom Column to 1.  That is working.  So I could perform a sum on the set of related rows and if > 0, then use the Max Incident Date for that related data set, otherwise set the value to the StartDate in udJob.

 

One twist to this is that there may be a NULL set of related rows if a Recordable event has not occurred.

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.