Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
zinminthant
Regular Visitor

How to find the latest value within a set of dates

Hello,

 

I have below table and couldn't find a way to find Activity where NPT happens. Please help to find the NPT Main Activity Column. 

Start TimeEnd TimeMain CategoryActivityNPT TypeNPT Main Activity
22-Jan-22 0:0023-Jan-22 23:15Main StageWeekly Drill  
22-Jan-22 20:1522-Jan-22 22:15  WeatherWeekly Drill
23-Jan-22 23:1524-Jan-22 2:30Main StageDaily Meeting  
24-Jan-22 2:3026-Jan-22 6:25Main StageDaily Meeting  
24-Jan-22 2:3024-Jan-22 3:50  WeatherDaily Meeting
24-Jan-22 3:5024-Jan-22 4:50  FacilityDaily Meeting

 

Best Regards,

Zin. 

1 ACCEPTED SOLUTION
v-cgao-msft
Community Support
Community Support

Hi @zinminthant ,

 

Please try creating a new calculated column.

 

NPT Main Activity = 
VAR _value_1 =
    IF ( 'Table'[NPT Type] <> BLANK (), 'Table'[Start Time] )
VAR _value_2 =
    CALCULATE (
        MAX ( 'Table'[Start Time] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Activity] <> BLANK () ),
        FILTER ( ALL ( 'Table' ), 'Table'[Start Time] < _value_1 )
    )
VAR _value_3 =
    CALCULATE (
        MAX ( 'Table'[End Time] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Start Time] = _value_2 )
    )
RETURN
    CALCULATE (
        MIN ( 'Table'[Activity] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Start Time] = _value_2 ),
        FILTER ( ALL ( 'Table' ), 'Table'[End Time] = _value_3 )
    )

 

The result should be like this.

vcgaomsft_0-1646368542555.png

Attach the PBIX file for reference. Hope it helps.

 

If this doesn't work for you, please consider sharing more details about it. And it would be great if there was a sample file without any sensitive information here.

 

It makes it easier to give you a solution.

  1. Sample (dummy dataset) data as text, use the table tool in the editing bar.
  2. Expected output from sample data.
  3. Explanation in words of how to get from 1. to 2.

 

Best Regards,
Community Support Team_Gao

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

4 REPLIES 4
v-cgao-msft
Community Support
Community Support

Hi @zinminthant ,

 

Please try creating a new calculated column.

 

NPT Main Activity = 
VAR _value_1 =
    IF ( 'Table'[NPT Type] <> BLANK (), 'Table'[Start Time] )
VAR _value_2 =
    CALCULATE (
        MAX ( 'Table'[Start Time] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Activity] <> BLANK () ),
        FILTER ( ALL ( 'Table' ), 'Table'[Start Time] < _value_1 )
    )
VAR _value_3 =
    CALCULATE (
        MAX ( 'Table'[End Time] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Start Time] = _value_2 )
    )
RETURN
    CALCULATE (
        MIN ( 'Table'[Activity] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Start Time] = _value_2 ),
        FILTER ( ALL ( 'Table' ), 'Table'[End Time] = _value_3 )
    )

 

The result should be like this.

vcgaomsft_0-1646368542555.png

Attach the PBIX file for reference. Hope it helps.

 

If this doesn't work for you, please consider sharing more details about it. And it would be great if there was a sample file without any sensitive information here.

 

It makes it easier to give you a solution.

  1. Sample (dummy dataset) data as text, use the table tool in the editing bar.
  2. Expected output from sample data.
  3. Explanation in words of how to get from 1. to 2.

 

Best Regards,
Community Support Team_Gao

 

If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

@v-cgao-msft 

 

Thank you. It is really great. 

 

Best Regards,

Zin. 

zinminthant
Regular Visitor

Hi @VahidDM 

 

Below is original table. NPT Type Start and End time falls inside the Main Stage Start and End time, and I would like to find out which Main Category and Activity it belongs to. 

Start TimeEnd TimeMain CategoryActivityNPT Type
22-Jan-22 0:0023-Jan-22 23:15Main StageWeekly Drill 
22-Jan-22 20:1522-Jan-22 22:15  Weather
23-Jan-22 23:1524-Jan-22 2:30Main StageDaily Meeting 
24-Jan-22 2:3026-Jan-22 6:25Main StageDaily Meeting 
24-Jan-22 2:3025-Jan-22 6:25Sub StageWalkaround 
24-Jan-22 2:3024-Jan-22 3:50  Weather
24-Jan-22 3:5024-Jan-22 4:50  Facility

Below table is what I expect with new column called NPT Main Activity. 

Start TimeEnd TimeMain CategoryActivityNPT TypeNPT Main Activity
22-Jan-22 0:0023-Jan-22 23:15Main StageWeekly Drill  
22-Jan-22 20:1522-Jan-22 22:15  WeatherWeekly Drill
23-Jan-22 23:1524-Jan-22 2:30Main StageDaily Meeting  
24-Jan-22 2:3026-Jan-22 6:25Main StageDaily Meeting  
24-Jan-22 2:3025-Jan-22 6:25Sub StageWalkaround  
24-Jan-22 2:3024-Jan-22 3:50  WeatherDaily Meeting
24-Jan-22 3:5024-Jan-22 4:50  FacilityDaily Meeting

Thanks in advance for your kind help. 

 

Best Regards,

Zin. 

VahidDM
Super User
Super User

Hi @zinminthant 

 

Can you please add more details to your question?? Please add the expected result table as per your sample data to make it clear.

 


Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.