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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

 

@v-jayw-msft 

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

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
v-rzhou-msft
Community Support
Community Support

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.