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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Yumikang
Helper II
Helper II

How to compare the time in the two tables which one is earlier?

Hi all,

I've watched a lot of videos and functions on my own, but none of them solved my problem, so I beg you to help me. I now have two forms,One is the vehicle entry form and the other is the vehicle inspection form.There is a date table between them that serves as a bridge to connect.The date table is 1 port, and the vehicle inspection table and vehicle admission table are multi-port.

1.  I would like to find out if the vehicle has been inspected at this month of year.

2.  And  to find out which vehicles were inspected before they entered the park.

Yumikang_0-1721637874938.png

Yumikang_1-1721639638035.png

Yumikang_2-1721639929255.png

I would like to compare the vehicles in the vehicle entry form with the vehicle inspection list to see if the vehicles entering the park have been inspected before entering the park.

I would like to create a new column in the vehicle entry table named "Inspected Vehicles1"

Analyze the vehicle inspection form and the vehicle entry form line by line, and first compare whether the entry form the column of" year and month" in the entry form are consistent with the column of "year and month" in the inspection form; If it is consistent, compare whether the license plate numbers in the two tables are the same, and return the license plate number if they are the same; If the time of "year and month" are inconsistent, the system is empty.

I would like to find out if the vehicle has been inspected at this month of year.

I would like to create a new column in the vehicle entry table named "Inspected Vehicles2"

Perform a line-by-line analysis of the vehicle entry form and the vehicle inspection form, first compare whether the entry time in the emtry form is earlier than the data in each row of the inspection table, and if so, return empty. If not, compare them line by line, and match the license plate number in the park entry checklist line by line in the inspection form. 

My goal was to find out which vehicles were inspected before they entered the park.

please help me,much appreciated.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi, @Yumikang 

You can try the following dax to achieve your need.

vyaningymsft_0-1721979650524.png

DAX:

currentMonthisIspection = 
IF (
    NOT (
        ISBLANK (
            LOOKUPVALUE (
                'Vechicle inspection form'[license plate number],
                'Vechicle inspection form'[license plate number], 'Vehicle entry form'[license plate number],
                'Vechicle inspection form'[YearMonth], 'Vehicle entry form'[YearMonth]
            )
        )
    ),
    'Vehicle entry form'[license plate number],
    "Null"
)


Checked prior to entry = 
VAR _entryDate = 'Vehicle entry form'[entry time]
VAR _plateNumber = 'Vehicle entry form'[license plate number]
VAR _year =
    YEAR ( 'Vehicle entry form'[entry time] )
VAR _month =
    MONTH ( 'Vehicle entry form'[entry time] )
VAR _day =
    DAY ( 'Vehicle entry form'[entry time] )
VAR _inspectionDate =
    LOOKUPVALUE (
        'Vechicle inspection form'[inspection date],
        'Vechicle inspection form'[license plate number], _plateNumber,
        'Vechicle inspection form'[inspection date],
            CALCULATE (
                MIN ( 'Vechicle inspection form'[inspection date] ),
                FILTER (
                    'Vechicle inspection form',
                    'Vechicle inspection form'[license plate number] = _plateNumber
                        && YEAR ( 'Vechicle inspection form'[inspection date] ) = _year
                        && MONTH ( 'Vechicle inspection form'[inspection date] ) = _month
                        && DAY ( 'Vechicle inspection form'[inspection date] ) > _day
                )
            )
    )
RETURN
    IF ( NOT ( ISBLANK ( _inspectionDate ) ), _plateNumber, "NUll" )

 

Best Regards,
Yang

Community Support Team

 

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 in the Power BI Forum

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Hi, @Yumikang 

You can try the following dax to achieve your need.

vyaningymsft_0-1721979650524.png

DAX:

currentMonthisIspection = 
IF (
    NOT (
        ISBLANK (
            LOOKUPVALUE (
                'Vechicle inspection form'[license plate number],
                'Vechicle inspection form'[license plate number], 'Vehicle entry form'[license plate number],
                'Vechicle inspection form'[YearMonth], 'Vehicle entry form'[YearMonth]
            )
        )
    ),
    'Vehicle entry form'[license plate number],
    "Null"
)


Checked prior to entry = 
VAR _entryDate = 'Vehicle entry form'[entry time]
VAR _plateNumber = 'Vehicle entry form'[license plate number]
VAR _year =
    YEAR ( 'Vehicle entry form'[entry time] )
VAR _month =
    MONTH ( 'Vehicle entry form'[entry time] )
VAR _day =
    DAY ( 'Vehicle entry form'[entry time] )
VAR _inspectionDate =
    LOOKUPVALUE (
        'Vechicle inspection form'[inspection date],
        'Vechicle inspection form'[license plate number], _plateNumber,
        'Vechicle inspection form'[inspection date],
            CALCULATE (
                MIN ( 'Vechicle inspection form'[inspection date] ),
                FILTER (
                    'Vechicle inspection form',
                    'Vechicle inspection form'[license plate number] = _plateNumber
                        && YEAR ( 'Vechicle inspection form'[inspection date] ) = _year
                        && MONTH ( 'Vechicle inspection form'[inspection date] ) = _month
                        && DAY ( 'Vechicle inspection form'[inspection date] ) > _day
                )
            )
    )
RETURN
    IF ( NOT ( ISBLANK ( _inspectionDate ) ), _plateNumber, "NUll" )

 

Best Regards,
Yang

Community Support Team

 

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 in the Power BI Forum

Anonymous
Not applicable

Hi, @Yumikang 

It's hard to understand the final effect you want to achieve by just reading the text you gave, you can share the pbix file without sensitive data for testing and share the final effect you want to achieve and the description of the logic to achieve it in the form of a screenshot. This will help you to solve the problem faster.

Best Regards,
Yang

Community Support Team

 

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 in the Power BI Forum

Thanks for the reply, I've got the test file ready, but how do I send the attachment? I didn't find the option to add an attachment.

Yumikang_1-1721702866143.png

 

Anonymous
Not applicable

Hi, @Yumikang 

You can use oneDrive or GoogleDrive to share the pbix file(Share the link).

Best Regards,
Yang

Community Support Team

Anonymous
Not applicable

Hi, @Yumikang 

Sorry, the links you shared doesn't open. I'm not a user in your organization.

vyaningymsft_0-1721711406009.png
If the amount of data used for the test is small, you can just copy your table, same as the posters below.
Solved: Return if one condition OR another is met - Microsoft Fabric Community
If you have a large amount of data, you can use GoogleDrive or OneDrive to share your links.
Solved: RANKX Measure failing to return correct results af... - Microsoft Fabric Community

Best Regards,
Yang

Community Support Team

 

Table 2: Vehicle inspection form

 

Inspection time inspection datelicense plate number
2024/6/6 14:262024/6/6赣CBM197
2024/6/6 14:302024/6/6粤AS3119
2024/6/6 14:322024/6/6粤A3E96Q
2024/6/6 14:342024/6/6粤A5V11T
2024/6/6 19:302024/6/6粤SC7896
2024/6/7 9:472024/6/7粤AAU516
2024/6/7 9:542024/6/7粤AAY123
2024/6/7 9:572024/6/7鄂FL5105
2024/6/7 15:462024/6/7粤WN2003
2024/6/7 15:512024/6/7皖N33046
2024/6/7 16:002024/6/7粤A38VN6
2024/6/11 12:022024/6/11粤BHY138
2024/6/12 10:132024/6/12桂P50183
2024/6/14 13:212024/6/14粤ABK276
2024/6/14 16:012024/6/13鲁Q395JE
2024/6/16 10:282024/6/16鄂FF7380
2024/6/16 14:012024/6/16粤SE8569
2024/6/16 14:032024/6/16粤SE7753
2024/6/24 9:122024/6/23豫D97738
2024/6/24 17:082024/6/24粤AAL951
2024/6/24 17:082024/6/24粤AAL993
2024/6/27 14:262024/6/29豫J76313
2024/6/27 14:262024/6/29豫JY773
2024/7/8 11:062024/7/8豫J76313
2024/7/16 19:422024/7/16粤AAS759
2024/7/18 14:432024/7/189.6飞翼
2024/7/19 8:502024/7/19粤AAN203
2024/7/19 9:012024/7/19鄂L57186
2024/7/19 15:532024/7/19粤AJD156
2024/7/20 14:172024/7/20赣C1155E
2024/7/20 14:192024/7/20

赣C3882E

Table 3: time form

date
202401
202402
202403
202404
202405
202406
202407
202408
202409
202410
202411
202412

The relationship I'm trying to model is this

Yumikang_0-1721713656754.png

I want to create 2 new columns in the vehicle entry table

1.Compare if this vehicle was inspected in a certain month. For example, if the entry time is 202406 in entry form, then look for 202406 in the vehicle inspection form to see if there is a license plate number for this vehicle.

If there is, return this license plate number, if not, return empty.

2.In a given month, compare whether the car was inspected before it was admitted to entry the park. For example, if the entry time of “粤 AA036” in the Vehicle Entry Table is 2024/06/23, then see if there is this license plate number in the Vehicle Inspection form between 2024/06/01 and 2024/06/22. If there is, return this license plate number, if not, return empty.

3.Table 3 shows my slicer, with which I filtered the formulated months.

 

thank for your reply.

Table 1: Vehicle Entry Form

license plate numberentry time
粤AAL0682024-04-27 15:42:00
粤AAL0682024-04-27 23:17:42
豫D977382024-04-27 22:16:00
粤BHY1382024-04-27 09:28:18
粤BHY1382024-04-27 19:40:33
粤SE85692024-04-27 20:13:56
皖N330462024-05-07 09:55:30
粤AAL0682024-05-07 10:28:48
皖A7S6882024-05-10 08:54:30
皖KZ23232024-05-10 18:37:44
粤AAN2032024-05-13 13:04:04
粤AH58402024-05-13 15:16:48
粤AFA7712024-05-14 09:48:48
粤AFA7712024-05-15 09:40:20
皖LG17442024-05-16 09:15:29
湘AL06862024-05-16 09:54:56
皖A7S5662024-05-16 14:59:15
粤AH58402024-05-16 15:13:48
粤A38VN62024-05-21 12:05:49
粤AFA7712024-05-22 09:18:31
粤AAL9512024-05-22 11:34:03
皖A7S5662024-05-22 14:43:12
粤AFA7712024-05-23 10:30:12
粤AGR8532024-05-23 12:30:15
皖A7Q0662024-05-23 12:29:41
粤SC78962024-06-15 19:48:08
鄂E364932024-06-16 10:49:19
鄂E364932024-06-16 20:52:37
粤SE85692024-06-16 09:55:04
鄂FF73802024-06-16 19:23:19
鄂FF73802024-06-16 19:11:29
粤BHY1382024-06-16 20:42:58
粤BMP6522024-06-17 07:46:34
豫P977382024-06-17 13:32:55
粤ABK2762024-06-24 14:48:52
皖A7S2992024-06-24 16:21:49
皖A7S2992024-06-24 14:49:05
粤AAL9932024-06-25 10:06:14
粤ABK2762024-06-25 10:08:28
皖A7J0992024-07-03 14:32:22
皖A7J0992024-07-03 14:32:32
粤AAU9182024-07-04 11:03:27
粤AA337772024-07-05 22:30:30
粤J25Q082024-07-15 10:37:10
皖A7N2992024-07-15 11:10:42
皖A7N2992024-07-15 11:10:29
粤WN20032024-07-19 11:32:07
粤WN20032024-07-19 11:17:15
鄂L571862024-07-19 11:42:15
鄂L571862024-07-19 11:42:26
粤ABK2762024-07-19 12:28:17
粤AFA7712024-07-19 14:50:15
粤ABK2762024-07-19 16:05:46
粤AJD1562024-07-20 08:55:08
粤ABK2762024-07-21 09:38:44
粤AAL9932024-07-22 09:33:19
粤AAU9182024-07-22 09:48:47
粤AFA7712024-07-22 10:48:23
粤AD94G12024-07-22 13:47:08
粤BMP6522024-06-17 17:07:15
粤SC78962024-06-17 09:26:43
粤SH55992024-06-17 10:43:59
粤SC78962024-06-17 17:38:36
皖N330462024-06-25 08:29:58
粤AAZ7072024-06-25 11:50:12
粤ABC3922024-06-24 08:38:24
豫P977382024-06-24 09:58:56
鲁Q395JE2024-06-24 12:37:29
粤BHY1382024-06-24 08:59:36
粤BMP6522024-06-25 11:00:35
鄂E364932024-06-25 16:14:05
鲁Q395JE2024-06-26 07:19:26
赣C3178E2024-06-25 08:42:51
粤BHY1382024-06-25 09:03:54
鄂FF73802024-06-26 06:03:55
赣C3178E2024-06-26 09:09:49
鄂FF73802024-06-26 06:03:44
鄂FF73802024-06-26 18:14:27
鄂FF73802024-06-26 18:14:18
沪D758182024-07-04 09:35:13
沪D758182024-07-04 16:42:50
皖N330462024-07-05 09:12:40
粤ABC3922024-07-04 14:51:18
沪D758182024-07-05 08:44:49
豫J763132024-07-05 13:24:51
赣C3882E2024-07-05 09:51:46
赣C3178E2024-07-05 08:48:04
鄂FLX7892024-07-05 16:47:33
鄂FLX7892024-07-05 16:47:25
粤ABC3922024-07-16 10:42:17
沪D758182024-07-19 07:34:53
沪ES27582024-07-19 08:35:54
沪D758182024-07-19 15:56:32
沪ES27582024-07-19 17:34:32
粤ABC3922024-07-19 10:53:47
粤ABC3922024-07-19 16:03:32
沪D758182024-07-20 11:04:45
皖N330462024-07-22 09:05:06
粤ABC3922024-07-20 13:50:37
沪D758182024-07-21 07:49:56
赣C3178E2024-07-21 09:30:58
赣C1303E2024-07-21 10:44:44
赣C1155E2024-07-21 10:05:45
粤SE85692024-07-21 11:27:12
沪ES27582024-07-21 10:48:57
沪ES27582024-07-21 20:56:14
沪D758182024-07-21 19:35:55
苏E212162024-07-21 13:07:05
赣C1155E2024-07-22 09:11:29
沪D758182024-07-22 07:41:07
沪DS82982024-07-22 19:26:47

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors