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
M_SBS_6
Helper V
Helper V

Column Calc based on new

Hi, 

I have a sales table of which goes back 10 years. Within this I have:

cust_id

items

date

 

What I'd like is a Column which will output the year of their first purchase. 

 

If purchase_date was made in 2023 but no record of purchase before then, then 2023 if first purchase date was made in 2022 then 2022 etc. 

 

The difficulty I think is based on someone buying multiple items

 

Cust_id.    items.            date.       New col

1.              Football.       01/02/2024 2023

1.              Rugby ball.   14/09/2023 2023

1.              Hockey stick. 12/06/2023 2023

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

It is for creating a new column.

 

Jihwan_Kim_0-1709827396189.png

 

 

INDEX function (DAX) - DAX | Microsoft Learn

 

expected_result_calculated_column = 
YEAR (
    MINX (
        INDEX (
            1,
            data,
            ORDERBY ( data[date], ASC ),
            ,
            PARTITIONBY ( data[cust_id] ),
            MATCHBY ( data[cust_id], data[items], data[date] )
        ),
        data[date]
    )
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

It is for creating a new column.

 

Jihwan_Kim_0-1709827396189.png

 

 

INDEX function (DAX) - DAX | Microsoft Learn

 

expected_result_calculated_column = 
YEAR (
    MINX (
        INDEX (
            1,
            data,
            ORDERBY ( data[date], ASC ),
            ,
            PARTITIONBY ( data[cust_id] ),
            MATCHBY ( data[cust_id], data[items], data[date] )
        ),
        data[date]
    )
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


DemoFour
Responsive Resident
Responsive Resident

You can try this as a calculated column @M_SBS_6  

First = 
CALCULATE(
MIN('Table'[Date]),
    FILTER(
        'Table',
        'Table'[Cust ID] = EARLIER( 'Table'[Cust ID])
    )
)

 

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.