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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
mak_tushar
Regular Visitor

Pull from a table the first transaction based on a date column.

I have a transaction table(A) with 4 columns say X, Y, Value and Date. I want to create a new table(B) from Table A such that Table B have unique transactions(rows) based on the combination of X and Y columns, and should pick only first transaction based on the date column. For example - 

Table A:

XYValueDate
X1Y1111-11-2022
X1Y1214-11-2022
X2Y2413-11-2022

 

Table B: It should only have one row for X1 and Y1 combination for date: 11-11-2022 as it is the first trasaction. 

XYValueDate
X1Y1111-11-2022
X2Y2413-11-2022

 

Thanks in advance.

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

Hi  @mak_tushar ,

 

Here are the steps you can follow:

1. Create calculated column.

Table 2 =
CALENDAR(
    MIN('Table'[Invoice Date]),MAX('Table'[Invoice Date]))

vyangliumsft_0-1669013189999.png

2. Create measure.

Flag =
var _select=SELECTEDVALUE('Table 2'[Date])
return
IF(
    MAX('Table'[Invoice Date])=
MINX(FILTER(ALL('Table'),'Table'[X]=MAX('Table'[X])&&'Table'[Y]=MAX('Table'[Y])&&'Table'[Location]=MAX('Table'[Location])&&'Table'[Invoice Date]>=_select),[Invoice Date]),1,0)

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_1-1669013189999.png

4. Result:

vyangliumsft_2-1669013190004.png

 

Best Regards,

Liu Yang

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

12 REPLIES 12
v-yangliu-msft
Community Support
Community Support

Hi  @mak_tushar ,

 

Here are the steps you can follow:

1. Create calculated column.

Table 2 =
CALENDAR(
    MIN('Table'[Invoice Date]),MAX('Table'[Invoice Date]))

vyangliumsft_0-1669013189999.png

2. Create measure.

Flag =
var _select=SELECTEDVALUE('Table 2'[Date])
return
IF(
    MAX('Table'[Invoice Date])=
MINX(FILTER(ALL('Table'),'Table'[X]=MAX('Table'[X])&&'Table'[Y]=MAX('Table'[Y])&&'Table'[Location]=MAX('Table'[Location])&&'Table'[Invoice Date]>=_select),[Invoice Date]),1,0)

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_1-1669013189999.png

4. Result:

vyangliumsft_2-1669013190004.png

 

Best Regards,

Liu Yang

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

Thanks @v-yangliu-msft, worked perfectly.

mak_tushar
Regular Visitor

This is part of the previous one. Actually Table A has data for past 3 years and I want to have data only after 1 Feb in the new table. - 

mak_tushar_0-1668781911751.png

 

FreemanZ
Super User
Super User

Try to create a new table with the code below:

B =

ADDCOLUMNS(

   SUMMARIZE (

       A,

       A[X],

       A[Y],

       A[Value]

    ) ,

   "Date",

   CALCULATE (MIN(A[Date]))

)

Is there a way to apply filter on the date as well? I want to pull records from table A that have invoice date greater than 1 feb.

is it a new requirement or in addition to the previous one?Or could you elaborate the expected table in Excel?

This is part of the previous one. Actually Table A has data for past 3 years and I want to have data only after 1 Feb in the new table. - 

mak_tushar_0-1668781911751.png

 

Then try this:

B =

CALCULATETABLE(

ADDCOLUMNS(

   SUMMARIZE (

       A,

       A[X],

       A[Y],

       A[Value]

    ) ,

   "Date",

   CALCULATE (MIN(A[Date]))

),

A[Date]>DATE(2022,1,1)

)

Getting duplicate rows (based on X and Y column).

 

how does the issue look like?

Is it an issue, considering you have different data in column Value and Date?

First two rows are duplicate as the first three coulmn values are same. Form these two(duplicate) rows, I want only the first row in my table as it has an older date. 

mak_tushar_0-1668834013840.png

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors