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
Mark88
Frequent Visitor

Filter value from a column

Hi,

 

I have a data set of more then 1M data lines. Below is a sample of this data set. The ID column is a text field and the ID's appear multiple times because they are active on multiple measurement dates. The measurement date is not unique, because multiple ID's can have the same measurement date. The last column contains the temperature measured on the specific date/time.

 

IDMeasurementDate                   Temperature                             
63473G861508034100123115-1-2019 10:5020,6
63473G861508034100123115-1-2019 11:0020,6
63473G861508034100123115-1-2019 11:1020,6
63473G861508034100123115-1-2019 11:2020,6
63473G861508034100123115-1-2019 11:3020,6
63473G861508034100123115-1-2019 11:4020,6
63473G861508034100123115-1-2019 11:5020,6
63473G861508034100123115-1-2019 12:0020,6
63473G861508034100123115-1-2019 12:1020,6
63473G861508034100123115-1-2019 12:2020,5
63473G861508034100123215-1-2019 10:5020,8
63473G861508034100123215-1-2019 11:0020,8
63473G861508034100123215-1-2019 11:1020,8
63473G861508034100123215-1-2019 11:2020,8
63473G861508034100123215-1-2019 11:3020,8
63473G861508034100123215-1-2019 11:4020,8
63473G861508034100123215-1-2019 11:5020,8
63473G861508034100123215-1-2019 12:0020,8
63473G861508034100123215-1-2019 12:1020,8
63473G861508034100123215-1-2019 12:2020,9
63473G861508034100123315-1-2019 10:5020,9
63473G861508034100123315-1-2019 11:0020,9
63473G861508034100123315-1-2019 11:1020,9
63473G861508034100123315-1-2019 11:2020,9
63473G861508034100123315-1-2019 11:3020,9
63473G861508034100123315-1-2019 11:4020,9
63473G861508034100123315-1-2019 11:5020,9
63473G861508034100123315-1-2019 12:0020,9
63473G861508034100123315-1-2019 12:1020,9
63473G861508034100123315-1-2019 12:2020,8

 

I want to create a new column that only shows the last temperature measured by the ID. These are the bold temperatures in my example. Can you please advise what formula I can use to arrange this?

1 ACCEPTED SOLUTION

Try these calculated columns;
DateRank = RANKX(FILTER(TempTable,TempTable[ID]=EARLIER(TempTable[ID])),TempTable[MeasurementDate],,DESC)

LastTemperatureReading = MINX(FILTER(TempTable,TempTable[ID]=EARLIER(TempTable[ID])&&TempTable[DateRank]=1),TempTable[Temperature])

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

View solution in original post

6 REPLIES 6
v-yiruan-msft
Community Support
Community Support

Hi @Mark88 ,

You can create a measure as below to get the last temperature:

Latest temperature = 
CALCULATE (
    MAX ( 'Measurement'[Temperature] ),
    FILTER (
        'Measurement',
        'Measurement'[ID] = MAX ( 'Measurement'[ID] )
            && 'Measurement'[MeasurementDate] = MAX ( 'Measurement'[MeasurementDate] )
    )
)

last temperature.JPG

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
AllisonKennedy
Super User
Super User

Not sure what the end goal is, this could be done using MEASURES, but if you absolutely need it as a column please explain why so we can provide more helpful response. You may be able to achieve it using the EARLIER function inside a calculated COLUMN.

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@AllisonKennedyThe actual table I have contains more columns. I require this measure in a seperate column (in the same table) because it's part of a couple of measurements I need to implement in this table to prepare my data. Most of the other measurements I already found out myself, but this one I'm unable to solve.

 

So in order to get my final result, I require this measurement in in a new column in the same table. I already tried to work with the EARLIER function, but I can't make it work.

Try these calculated columns;
DateRank = RANKX(FILTER(TempTable,TempTable[ID]=EARLIER(TempTable[ID])),TempTable[MeasurementDate],,DESC)

LastTemperatureReading = MINX(FILTER(TempTable,TempTable[ID]=EARLIER(TempTable[ID])&&TempTable[DateRank]=1),TempTable[Temperature])

Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

@AllisonKennedyThanks a lot for your help! The RANKX formula helped me to solve the issue. The MINX formula also worked, but this showed me the last temperature in every cell of the column. I only needed the last temperature and the other cells being blank. I solved this via an IF formula.

 

Also thanks to @v-yiruan-msft and @amitchandak for your time!

amitchandak
Super User
Super User

@Mark88 , This should work as a measure along with ID

lastnonblankvalue(Table[MeasurementDate],Table[Temperature])

new Table

Summarize(Table,Table[ID], "Last Value",lastnonblankvalue(Table[MeasurementDate],Table[Temperature]))

 

New Measure =

Sumx(Summarize(Table,Table[ID], "Last Value",lastnonblankvalue(Table[MeasurementDate],Table[Temperature])),[Last Value])

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.