cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
dolevh
Helper II
Helper II

create a new table with min date of price column

Hi all, 

 

I have this table:  

 

Table Name: Customers

   ID   Date   Price
   123   1/1/2021  Blank
   123   2/1/2021  0
   123   3/1/2021  100
   123   4/1/2021  200
   321   1/1/2021  99,999,999
   321   2/1/2021  50
   45678   1/1/2021  Blank
   45678   2/1/2021  0
   45678   3/1/2021  1,000

 

and now, I want to create a new table that shows me just the unique ID with the first price that is greater than 0 and less than 2M.

 

Table Name: CustomersUniqueValue

   ID   Date   Price
   123   3/1/2021   100
   321   2/1/2021   50
   45678   3/1/2021   1,000

 

how can I create just the column Price with the Min Date that the first price is greater than 0 and less than 2M?

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

Hi  @dolevh ,

Here are the steps you can follow:

1. Create calculated column.

Flag =
    MINX(FILTER(ALL('Table'),
'Table'[ID]=EARLIER('Table'[ID])&&
'Table'[Price] >0&&
'Table'[Price]<200&&
'Table'[Price]<>BLANK()),[Price])
Flag1 =
IF(
    'Table'[Date]=
MAXX(FILTER(ALL('Table'),'Table'[Flag]<>BLANK()&&
'Table'[Flag]='Table'[Price]&&'Table'[ID]=EARLIER('Table'[ID])),[Date]),1,0)

2. Create calculated table.

Table2 =
var _table1=
FILTER(ALL('Table'),'Table'[Flag1]=1)
return
SUMMARIZE(
    _table1,
    [ID],[Date],[Price])

3. Result:

vyangliumsft_0-1656304059513.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

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi  @dolevh ,

Here are the steps you can follow:

1. Create calculated column.

Flag =
    MINX(FILTER(ALL('Table'),
'Table'[ID]=EARLIER('Table'[ID])&&
'Table'[Price] >0&&
'Table'[Price]<200&&
'Table'[Price]<>BLANK()),[Price])
Flag1 =
IF(
    'Table'[Date]=
MAXX(FILTER(ALL('Table'),'Table'[Flag]<>BLANK()&&
'Table'[Flag]='Table'[Price]&&'Table'[ID]=EARLIER('Table'[ID])),[Date]),1,0)

2. Create calculated table.

Table2 =
var _table1=
FILTER(ALL('Table'),'Table'[Flag1]=1)
return
SUMMARIZE(
    _table1,
    [ID],[Date],[Price])

3. Result:

vyangliumsft_0-1656304059513.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

dolevh
Helper II
Helper II

Hi All, 

 

Someone know how can I create just the column Price with the Min Date that the first price is greater than 0 and less than 2M? 

 

Thanks again!

Maybe try this for your calculated table.  It might not be the most efficient depending on the size of your Customers table (both columns and rows) since it is being copied temporarily.  It's not how I'd usually attempt this but it seemed like the easiest.

 

Anyone...  Please let me know if this is a bad practice since I'm pretty new at this.

 

 

FirstPrices =
VAR _Table1 =
FILTER ( Customers, Customers[Price] > 0 && Customers[Price] < 2000000 )
VAR _Table2 =
ADDCOLUMNS (
_Table1,
"MinDate", CALCULATE ( MINX ( FILTER ( _Table1, [ID] = MAX ( Customers[ID] ) ), [Date] ) )
)
VAR _Table3 =
FILTER ( _Table2, [Date] = [MinDate] )
RETURN
SELECTCOLUMNS ( _Table3, "ID", [ID], "MinDate", [MinDate], "Price", [Price] )

 

Helpful resources

Announcements
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors