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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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