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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.