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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
NickProp28
Post Partisan
Post Partisan

Apply condition in Power Query (Filter earliest date based on each Consol ID)

Dear Community,

 

I would like to apply some condition when do the data cleansing in Power Query.

NickProp28_6-1628847317175.png

**Only need one date record for each Consol ID**

NickProp28_7-1628847338673.png

ETD (DD/MM/YYYY)

Condition as below: 

i.) Date with 'Null' shouldnt be choosen as earliest date when there have available date for that Consol ID.

For example:  C001 with date '1/1/2021' should be selected as earliest date, but C002 doesnt have other available date. In this case, 'Null' can be selected.

 

ii.) If the Consol ID have few transport mode (SEA or AIR ,RAI,ROA), ONLY priorities on the earliest date of 'SEA' or 'AIR' transport mode.

For example: In C003, even the earliest date is 1/1/2021, but we only focus on the date with transport mode 'SEA' or 'AIR'. So earliest date for C003 is 1/3/2021, while C004 is 1/6/2021.

 

iii.) If there is only one trasport mode (RAI or ROA), the earliest date will be selected.

For example: '1/1/2021' for C005 and C006. 

 

Here attached with the pbix: https://ufile.io/twdwgzh8

 

Thanks for your attention.

Any assitance you can provide would be greatly appreciated!

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @NickProp28 

try this

Column = 
VAR _t =
    CALCULATE (
        COUNT ( Consol_Date[ConsolID] ),
        FILTER (
            ALLEXCEPT ( Consol_Date, Consol_Date[ConsolID] ),
            Consol_Date[Transport] = "SEA"
                || Consol_Date[Transport] = "AIR"
        )
    )
RETURN
    IF (
        _t >= 1,
        CALCULATE (
            MIN ( Consol_Date[ETD] ),
            FILTER (
                ALLEXCEPT ( Consol_Date, Consol_Date[ConsolID] ),
                Consol_Date[Transport] = "SEA"
                    || Consol_Date[Transport] = "AIR"
            )
        ),
        CALCULATE (
            MIN ( Consol_Date[ETD] ),
            ALLEXCEPT ( Consol_Date, Consol_Date[ConsolID] )
        )
    )

result

vxiaotang_0-1629106865124.png

 

Best Regards,

Community Support Team _Tang

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

View solution in original post

3 REPLIES 3
v-xiaotang
Community Support
Community Support

Hi @NickProp28 

try this

Column = 
VAR _t =
    CALCULATE (
        COUNT ( Consol_Date[ConsolID] ),
        FILTER (
            ALLEXCEPT ( Consol_Date, Consol_Date[ConsolID] ),
            Consol_Date[Transport] = "SEA"
                || Consol_Date[Transport] = "AIR"
        )
    )
RETURN
    IF (
        _t >= 1,
        CALCULATE (
            MIN ( Consol_Date[ETD] ),
            FILTER (
                ALLEXCEPT ( Consol_Date, Consol_Date[ConsolID] ),
                Consol_Date[Transport] = "SEA"
                    || Consol_Date[Transport] = "AIR"
            )
        ),
        CALCULATE (
            MIN ( Consol_Date[ETD] ),
            ALLEXCEPT ( Consol_Date, Consol_Date[ConsolID] )
        )
    )

result

vxiaotang_0-1629106865124.png

 

Best Regards,

Community Support Team _Tang

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

amitchandak
Super User
Super User

@NickProp28 , Try a new column like

 

new column =
var _min = minx(filter(Table, [Consol ID] =earlier([Consol ID]) ),[Date])
var _count = countx(filter(Table, [Consol ID] =earlier([Consol ID]) && not [transport mode] in {"SEA","AIR"}),[Date])+0
var _min2 = countx(filter(Table, [Consol ID] =earlier([Consol ID]) && [transport mode] in {"SEA","AIR"}),[Date])
return
if(_count >=1, _min2, _min)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Dear @amitchandak ,

 

Thanks for your prompt response. 

But after I applied the code you provided. 

C003 until C005 retrieved null and invalid date.

NickProp28_0-1628918187090.png

C004 and C005, if there's only one transport mode (No matter is ROA/ROI) . The earliest date will be selected. 

Kindly advice.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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.