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
FahQ2022
Frequent Visitor

Need help to create an event based on comparing two columns and each row of data

Attached excel file contains the data set. 

What I am trying to accomplish in Power BI is  

 

There is an Entered Data and a Served Date and air craft number 

 

What I need is a column to say that this group 1 , then group 2 , group 3 etc....

check if f2 is greater than e2 then start with e2 and f2 is maximum
if e3 less than f2 then e2 Is minimum value and f3 is maximum
if e4 less than f3 then e2 is minimum and f4 is greater than f3 , if f4 is less than f3 then f3 still remains maximum
if e5 is greater than the minimum value then e2 is minimum, check if f5 greater than maximum , if not then f3 is maximum

 

I am trying to attach a file but I can't

so I am entering excel , i am trying to get EVENT column using Dax formula or M code whichever is easy 

 

IndexAircraftDE idEventStartStopDuration (days)Event minimum maximum  
1101DE_101_01Record_31-Jan-229-Feb-2239Event 1 - 101 e2f2 check if f2 is greater than e2 then start with e2 and f2 is maximum
2101DE_101_01Record_13-Jan-2217-Feb-2245Event 1 - 101 e2f3 if e3 less than f2 then e2 Is minimum value and f3 is maximum
3101DE_101_01Record_29-Jan-227-Feb-2229Event 1 - 101 e2f3 if e4 less than f3 then e2 is minimum and f4 is greater than f3 , if f4 is less than f3 then f3 still remains maximum
4101DE_101_01Record_45-Feb-2212-Feb-227Event 1 - 101 e2f3 if e5 is greater than the minimum value then e2 is minimum, check if f5 greater than maximum , if not then f3 is maximum
5101DE_101_02Record_522-Feb-223-Mar-229Event 2 - 101 e6f6  
6101DE_101_02Record_727-Feb-221-Mar-222Event 2 - 101 e6f6  
7101DE_101_02Record_61-Mar-228-Mar-227Event 2 - 101 e6f8  
8102DE_102_01Record_83-Feb-227-Feb-22 Event 1 - 102     
9102DE_102_01Record_94-Feb-2214-Feb-22 Event 1 - 102     
10102DE_102_01Record_109-Feb-2225-Mar-22 Event 1 - 102     
4 REPLIES 4
FahQ2022
Frequent Visitor

Basically , I am trying to capture a downing event. The downing event is when an aircraft is out of service. There are two dates, [Entered Date] and [Servicable Date]

 

Below are 3 examples of a downing event

 

Index

AircraftEntered DateServicable DateEvent minimum maximum
11011-Jan-229-Feb-22Event 1 - 101 e2f2
21013-Jan-2217-Feb-22Event 1 - 101 e2f3
31019-Jan-227-Feb-22Event 1 - 101 e2f3
41015-Feb-2212-Feb-22Event 1 - 101 e2f3
510122-Feb-223-Mar-22Event 2 - 101 e6f6
610127-Feb-221-Mar-22Event 2 - 101 e6f6
71011-Mar-228-Mar-22Event 2 - 101 e6f8
81023-Feb-227-Feb-22Event 1 - 102   
91024-Feb-2214-Feb-22Event 1 - 102   
101029-Feb-2225-Mar-22Event 1 - 102   

 

The minimum and maximum values are the ranges for each downing event which I have put for logic purposes 

 

For the first record (Index 1)

the assumption is the minimum value is row 2 as mentioned e2 (Entered date) and the maximum value is f2 (Sevicable date) this is the start of the downing event.  

 

For the second record (Index 2) row 3

(e3) will check if e3 is less than f2 (servicable date) if yes then this record is part of the same downing event and if f2 < f3 then f3 is now the new servicable date instead of f2 for this downing event. So the current range of the downing event went from (1 Jan - 9 Feb) => (Jan 1 - 17 Feb) .  

 

For the 3rd record (Index 3) 4th row

e4 will check if its less than f3, if yes then this record is part of the same downing event and if f4 (Feb 7 )< f3 ( Feb 17) , current range for the 1st downing event is [e2....f3] [Jan 1 - Feb 17]  

 

For the 4th (Index 4) record, 5th row

      e5 will check if its less than f3(maximum range point) , if yes then this record is part of the          same downing event and if f5 (Feb 9 )< f3 ( Feb 17) , current range for the 1st downing event is [e2....f3] [Jan 1 - Feb 17]  

 

For the 5th (Index 5) record, 6th row

      e6 will check if its less than f3(maximum range point) , if yes then this record is part of the          same downing event else new downing event starts as e6 is greater than f3

      So in the event column it will be Event 2 +101 (Aircraft number) and the new range for this        downing event will start from  [e6 ..f6]  (Feb 22 ...... Mar9)  

 

 

v-rzhou-msft
Community Support
Community Support

Hi @FahQ2022 ,

 

According to your statement, I think your maximum/minimum is calculated based on the previous data. So you need to use looping in your calculation. As far as I know, Dax doesn't support looping. Here I suggest you to try M code to create a custom column in Power Query Editor.

For reference:

Power Query Loop Calculation

List.Generate() and Looping in PowerQuery

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Rico

 

I am not familiar with M , if someone can write the M code it would be greatly appreciated

 

Thanks

Hi @FahQ2022 

 

can't follow your description here:

 

What I need is a column to say that this group 1 , then group 2 , group 3 etc....

check if f2 is greater than e2 then start with e2 and f2 is maximum
if e3 less than f2 then e2 Is minimum value and f3 is maximum
if e4 less than f3 then e2 is minimum and f4 is greater than f3 , if f4 is less than f3 then f3 still remains maximum
if e5 is greater than the minimum value then e2 is minimum, check if f5 greater than maximum , if not then f3 is maximum

 

can you rephrase it somehow?

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.