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
jr3151006
Helper IV
Helper IV

Cars- how to evaluate First date seen + Price and also lastest date + price

Hi,

 

given that table, just created for example, we need:

1) list as distinct the 'Car' collumn but, based on it's 'Date' collumn, ordering by the lastest 10 records;

2) For each 'car', we need get the first 'date' + price; also get the lastest date + price in order to draw a graph for price evolution.

 

Any help on best strategies to accomplish that will be appreciated.

 

Table

####
PBI-Cars-TableandPrices.PNG

----

 

Desired results from the source table + Desired Graph 

########################################
PBI-Cars-TableandPrices-DESIRED.PNG

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

Hi  @jr3151006 ,

Here are the steps you can follow:

Desired results from the source table 

1. Create measure.

First Value =
var _mindate=MINX(FILTER(ALL(TableCarsamdPrices),'TableCarsamdPrices'[Car]=MAX('TableCarsamdPrices'[Car])),[Date])
return
CALCULATE(SUM('TableCarsamdPrices'[Value]),FILTER(ALL(TableCarsamdPrices),'TableCarsamdPrices'[Car]=MAX('TableCarsamdPrices'[Car])&&'TableCarsamdPrices'[Date]=_mindate))
LastValue =
var
_maxdate=MAXX(FILTER(ALL(TableCarsamdPrices),'TableCarsamdPrices'[Car]=MAX('TableCarsamdPrices'[Car])),[Date])
return
CALCULATE(SUM('TableCarsamdPrices'[Value]),FILTER(ALL(TableCarsamdPrices),'TableCarsamdPrices'[Car]=MAX('TableCarsamdPrices'[Car])&&'TableCarsamdPrices'[Date]=_maxdate))

2. Result:

vyangliumsft_0-1647914430233.png

Desired Graph :

1. Using Enter data, create a table.

vyangliumsft_1-1647914430234.png

2. Create calculated column.

Value =
SWITCH(
    TRUE(),
    'Table'[First_Last]="First Value", CALCULATE(SUM('TableCarsamdPrices'[Value]),FILTER(ALL(TableCarsamdPrices),'TableCarsamdPrices'[Date]=
    MINX(FILTER(ALL('TableCarsamdPrices'),[Car]=EARLIER('Table'[Car])),[Date])&&'Table'[Car]=EARLIER('Table'[Car]))),
    'Table'[First_Last]="Lastest Value",  CALCULATE(SUM('TableCarsamdPrices'[Value]),FILTER(ALL(TableCarsamdPrices),'TableCarsamdPrices'[Date]=
    MaxX(FILTER(ALL('TableCarsamdPrices'),[Car]=EARLIER('Table'[Car])),[Date])&&'Table'[Car]=EARLIER('Table'[Car]))))

vyangliumsft_2-1647914430234.png

3.Result.

vyangliumsft_3-1647914430238.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

5 REPLIES 5
v-yangliu-msft
Community Support
Community Support

Hi  @jr3151006 ,

Here are the steps you can follow:

Desired results from the source table 

1. Create measure.

First Value =
var _mindate=MINX(FILTER(ALL(TableCarsamdPrices),'TableCarsamdPrices'[Car]=MAX('TableCarsamdPrices'[Car])),[Date])
return
CALCULATE(SUM('TableCarsamdPrices'[Value]),FILTER(ALL(TableCarsamdPrices),'TableCarsamdPrices'[Car]=MAX('TableCarsamdPrices'[Car])&&'TableCarsamdPrices'[Date]=_mindate))
LastValue =
var
_maxdate=MAXX(FILTER(ALL(TableCarsamdPrices),'TableCarsamdPrices'[Car]=MAX('TableCarsamdPrices'[Car])),[Date])
return
CALCULATE(SUM('TableCarsamdPrices'[Value]),FILTER(ALL(TableCarsamdPrices),'TableCarsamdPrices'[Car]=MAX('TableCarsamdPrices'[Car])&&'TableCarsamdPrices'[Date]=_maxdate))

2. Result:

vyangliumsft_0-1647914430233.png

Desired Graph :

1. Using Enter data, create a table.

vyangliumsft_1-1647914430234.png

2. Create calculated column.

Value =
SWITCH(
    TRUE(),
    'Table'[First_Last]="First Value", CALCULATE(SUM('TableCarsamdPrices'[Value]),FILTER(ALL(TableCarsamdPrices),'TableCarsamdPrices'[Date]=
    MINX(FILTER(ALL('TableCarsamdPrices'),[Car]=EARLIER('Table'[Car])),[Date])&&'Table'[Car]=EARLIER('Table'[Car]))),
    'Table'[First_Last]="Lastest Value",  CALCULATE(SUM('TableCarsamdPrices'[Value]),FILTER(ALL(TableCarsamdPrices),'TableCarsamdPrices'[Date]=
    MaxX(FILTER(ALL('TableCarsamdPrices'),[Car]=EARLIER('Table'[Car])),[Date])&&'Table'[Car]=EARLIER('Table'[Car]))))

vyangliumsft_2-1647914430234.png

3.Result.

vyangliumsft_3-1647914430238.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

Whitewater100
Solution Sage
Solution Sage

Hello:

 For First Date and Entry questions, I'll assume the table is named table. I don't think you have a date calendar and it really would be a great idea. With this in mind, 

First Date = FIRSTNONBLANK(Table[Date].[Date], SUM(Table[Value]))

First Date = FIRSTNONBLANKVALUE(Table[Date].[Date], SUM(Table[Value]))

and do the same thing for LASTNONBLANK & LASTNONBLANKVALUE.

 

I hope this works for you.

jr3151006
Helper IV
Helper IV

Can I use 'Power Query M' to reference the source table, group by 'car' and them discover the first value and the lastest value?

amitchandak
Super User
Super User

@jr3151006 , Try measures like

 

First = Calculate(firstnonblank(Table[Date],Max(Table[Value])))


Last = Calculate(lastnonblank(Table[Date],Max(Table[Value])))

 

or


First = Calculate(firstnonblank(Table[Date],Max(Table[Value])), allexcept(Table, Table[Car]))


Last = Calculate(lastnonblank(Table[Date],Max(Table[Value])), allexcept(Table, Table[Car]))

Hi @amitchandak,

 

tks for reply, but that DAX indiscriminate the 'car' and just collect the old one and new records.

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.