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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Samhunt
Helper II
Helper II

Need help to get a min date value

Hello everyone, 

 

I have two tables 'Sales Data' and 'Accommodations'. 

 

I want to import the first date that an accommodation was first rented from the sales data table and put it in a new column in accommodations table. 

 

The column with the matching data is called  'accommodation' in both tables and the table with the dates its called 'date'

Thank you 

 

2 ACCEPTED SOLUTIONS
123abc
Community Champion
Community Champion

Certainly! In Power BI, you can achieve this by creating a relationship between the 'Accommodations' table and the 'Sales Data' table based on the 'accommodation' column. Once you establish the relationship, you can use DAX (Data Analysis Expressions) to create a new column in the 'Accommodations' table that fetches the minimum date from the 'date' column in the 'Sales Data' table.

Here's a step-by-step guide:

  1. Load Your Data: Ensure that both 'Accommodations' and 'Sales Data' tables are loaded into Power BI.

  2. Create a Relationship: In the 'Relationships' view, create a relationship between the 'accommodation' column in the 'Accommodations' table and the 'accommodation' column in the 'Sales Data' table.

  3. Create a New Column: In the 'Accommodations' table, go to the 'Model' view, select the table, and click on 'New column' in the 'Modeling' tab.

  4. Write DAX Formula: Write a DAX formula to fetch the minimum date from the 'date' column in the 'Sales Data' table for each 'accommodation' in the 'Accommodations' table. Use the RELATEDTABLE and MINX functions. Here's an example:

DAX Measure:

MinDate = MINX(RELATEDTABLE('Sales Data'), 'Sales Data'[date])

 

  1. This formula uses RELATEDTABLE to get a table of related 'Sales Data' rows for each 'Accommodation' and then uses MINX to find the minimum date in that table.

  2. Apply Changes: After creating the new column, click on 'Apply Changes' to apply the changes to your data model.

Now, your 'Accommodations' table should have a new column ('MinDate') that contains the minimum date from the 'Sales Data' table for each 'accommodation'. You can use this column in your reports and visuals.

Remember to adjust column and table names according to your actual dataset.

 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

 

 

View solution in original post

Anonymous
Not applicable

 Hi @Samhunt

 

I have understood about your problem, here is the solution I offer:

 

Here are the data of the two tables

 

'Sales Data'

vnuocmsft_0-1702886007135.png

'accommodations'

vnuocmsft_1-1702886034552.png

 

Make sure that there is a relationship between the two tables based on the 'accommodation' column. If there is no relationship between the two tables in the "Model View", you can create them manually, dragging the 'accommodation' field from one table to the 'accommodation' field in the other table.

vnuocmsft_2-1702886056898.png

 

Use the following DAX formula to calculate the minimum date:

vnuocmsft_3-1702886068652.png

 

First rented date = MIN('Sales Data'[date])

 

 

If there is no relationship between the two tables, you can also use a different DAX:

vnuocmsft_4-1702886109245.png

 

First rented date2 = CALCULATE(
    MIN('Sales Data'[date]),
    FILTER(
       'Sales Data',
        'Sales Data'[accommodation] = MAX('Accommodations'[accommodation])
    )
)

 

 

 

Here is the result

vnuocmsft_5-1702886140179.png

If you're still having problems, provide some dummy data and the desired outcome. It is best presented in the form of a table.

 

Best Regards,

Nono Chen

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 @Samhunt

 

I have understood about your problem, here is the solution I offer:

 

Here are the data of the two tables

 

'Sales Data'

vnuocmsft_0-1702886007135.png

'accommodations'

vnuocmsft_1-1702886034552.png

 

Make sure that there is a relationship between the two tables based on the 'accommodation' column. If there is no relationship between the two tables in the "Model View", you can create them manually, dragging the 'accommodation' field from one table to the 'accommodation' field in the other table.

vnuocmsft_2-1702886056898.png

 

Use the following DAX formula to calculate the minimum date:

vnuocmsft_3-1702886068652.png

 

First rented date = MIN('Sales Data'[date])

 

 

If there is no relationship between the two tables, you can also use a different DAX:

vnuocmsft_4-1702886109245.png

 

First rented date2 = CALCULATE(
    MIN('Sales Data'[date]),
    FILTER(
       'Sales Data',
        'Sales Data'[accommodation] = MAX('Accommodations'[accommodation])
    )
)

 

 

 

Here is the result

vnuocmsft_5-1702886140179.png

If you're still having problems, provide some dummy data and the desired outcome. It is best presented in the form of a table.

 

Best Regards,

Nono Chen

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

 

123abc
Community Champion
Community Champion

Certainly! In Power BI, you can achieve this by creating a relationship between the 'Accommodations' table and the 'Sales Data' table based on the 'accommodation' column. Once you establish the relationship, you can use DAX (Data Analysis Expressions) to create a new column in the 'Accommodations' table that fetches the minimum date from the 'date' column in the 'Sales Data' table.

Here's a step-by-step guide:

  1. Load Your Data: Ensure that both 'Accommodations' and 'Sales Data' tables are loaded into Power BI.

  2. Create a Relationship: In the 'Relationships' view, create a relationship between the 'accommodation' column in the 'Accommodations' table and the 'accommodation' column in the 'Sales Data' table.

  3. Create a New Column: In the 'Accommodations' table, go to the 'Model' view, select the table, and click on 'New column' in the 'Modeling' tab.

  4. Write DAX Formula: Write a DAX formula to fetch the minimum date from the 'date' column in the 'Sales Data' table for each 'accommodation' in the 'Accommodations' table. Use the RELATEDTABLE and MINX functions. Here's an example:

DAX Measure:

MinDate = MINX(RELATEDTABLE('Sales Data'), 'Sales Data'[date])

 

  1. This formula uses RELATEDTABLE to get a table of related 'Sales Data' rows for each 'Accommodation' and then uses MINX to find the minimum date in that table.

  2. Apply Changes: After creating the new column, click on 'Apply Changes' to apply the changes to your data model.

Now, your 'Accommodations' table should have a new column ('MinDate') that contains the minimum date from the 'Sales Data' table for each 'accommodation'. You can use this column in your reports and visuals.

Remember to adjust column and table names according to your actual dataset.

 

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

 

In case there is still a problem, please feel free and explain your issue in detail, It will be my pleasure to assist you in any way I can.

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors