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
Jan-H
New Member

Problem with Creating new column based on multiple coditions

I need to generate a column in Maintenance that equals 1 if:

  1. Car is registered in 2010 (other table linked to maintenance table)
  2. Maintenance is done in for the first time in that year (if a car has multiple maintenances in a year it should only show a 1 for the first maintenance of that year)

 

JanH_0-1633084506578.png

 

@Anonymous 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Jan-H 

Car Table

3.png

Add a Year column in Matintenance Table.

2.png

Year = YEAR(Maintenance[Date of Maintenance])

Then try this code.

Flag 1 =
VAR _MinDateEachYear =
    CALCULATE (
        MIN ( Maintenance[Date of Maintenance] ),
        FILTER ( Maintenance, Maintenance[Year] = EARLIER ( Maintenance[Year] ) )
    )
RETURN
    IF (
        AND (
            RELATED ( Car[Registration year] ) = 2010,
            Maintenance[Date of Maintenance] = _MinDateEachYear
        ),
        1,
        BLANK ()
    )

Result is as below.

1.png

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.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Jan-H 

Car Table

3.png

Add a Year column in Matintenance Table.

2.png

Year = YEAR(Maintenance[Date of Maintenance])

Then try this code.

Flag 1 =
VAR _MinDateEachYear =
    CALCULATE (
        MIN ( Maintenance[Date of Maintenance] ),
        FILTER ( Maintenance, Maintenance[Year] = EARLIER ( Maintenance[Year] ) )
    )
RETURN
    IF (
        AND (
            RELATED ( Car[Registration year] ) = 2010,
            Maintenance[Date of Maintenance] = _MinDateEachYear
        ),
        1,
        BLANK ()
    )

Result is as below.

1.png

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.

jppv20
Solution Sage
Solution Sage

Hi @Jan-H ,

 

Can you provide some example data from your table?

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.