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
cyberblitz
Helper II
Helper II

Find last value by date

I am struggling to solve this. I have searched and tried numerous formulas to no avail. The dataset is thus(sorry about the formatting):

District Facility Shift                 Rooms ModifiedAt

hotels   hotel1   Night 9:00 pm    22      12/06/2020 08:46:50
hotels   hotel1   AM 7:00 am        24     12/06/2020 08:46:40
hotels   hotel1   AM 7:00 am        0       12/06/2020 08:46:30
hotels   hotel2   PM 3:00 pm        5      12/06/2020 07:38:50
hotels   hotel2   Night 9:00 pm    4      12/06/2020 07:38:40
hotels   hotel1   Night 9:00 pm    23    11/06/2020 17:29:50
hotels   hotel1   PM 3:00 pm        22    11/06/2020 17:12:40
hotels   hotel1   Night 9:00 pm    23    11/06/2020 17:12:30
hotels   hotel2   PM 3:00 pm        5     11/06/2020 15:27:50
hotels   hotel2   Night 9:00 pm    4     11/06/2020 15:26:40
hotels   hotel2   Night 9:00 pm    5     11/06/2020 15:26:30
hotels   hotel2   PM 3:00 pm        4     11/06/2020 15:26:50
hotels   hotel2   Night 9:00 pm    5     11/06/2020 15:26:40
hotels   hotel2   Night 9:00 pm    5     11/06/2020 15:26:30
hotels   hotel1   Night 9:00 pm    22    11/06/2020 08:47:50
hotels   hotel1   PM 3:00 pm        20   11/06/2020 08:47:40
hotels   hotel1   AM 7:00 am        22   11/06/2020 08:47:30
hotels   hotel1   PM 3:00 pm       20    11/06/2020 08:46:50
hotels   hotel1   AM 7:00 am       22    11/06/2020 08:46:40
hotels   hotel2   Tomorrow AM   5      11/06/2020 08:06:30
hotels   hotel2   PM 3:00 pm       4      11/06/2020 08:06:20
hotels   hotel2   AM 7:00 am       4      11/06/2020 08:06:10
hotels   hotel1   Night 9:00 pm   22    11/06/2020 07:13:50
hotels   hotel1   Night 9:00 pm   2      11/06/2020 07:13:40
hotels   hotel1   Night 9:00 pm   24    11/06/2020 07:13:30
hotels   hotel1   PM 3:00 pm      20    11/06/2020 07:13:20
hotels   hotel1   PM 3:00 pm      24    11/06/2020 07:13:10
hotels   hotel1   AM 7:00 am      22    11/06/2020 07:13:05
hotels   hotel1   Night 9:00 pm  24    11/06/2020 07:12:50
hotels   hotel1   PM 3:00 pm      24    11/06/2020 07:12:50
hotels   hotel1   AM 7:00 am      24    11/06/2020 07:12:40
hotels   hotel1   Night 9:00 pm   24   11/06/2020 07:12:30
hotels   hotel1   PM 3:00 pm      24    11/06/2020 07:12:20
hotels   hotel1   AM 7:00 am      24    11/06/2020 07:12:10
hotels   hotel2   AM 7:00 am      5      11/06/2020 01:00:50
hotels   hotel2   AM 7:00 am      6      11/06/2020 01:00:40
hotels   hotel2   Tomorrow AM  4      10/06/2020 08:37:50
hotels   hotel2   AM 7:00 am      6      10/06/2020 08:37:40
hotels   hotel2   Night 9:00 pm  5      10/06/2020 08:37:50
hotels   hotel2   Night 9:00 pm  6      10/06/2020 08:37:40
hotels   hotel2   AM 7:00 am     5      10/06/2020 08:37:30

 

I have tried formulas similar to these, and then some:

 

 

 

 

max('Sheet1 (2)'[ModifiedAt]) return maxx(FILTER('Sheet1',[ModifiedAt] = maxDate),'Sheet1'[Rooms])
Max Date = 
VAR CurrentName = 'Survey table'[Name]

RETURN
MAXX(
   FILTER( ALL( 'Survey table' ), 'Survey table'[Name] = CurrentName ),
        'Survey table'[Date Taken] )

 

 

 

 

But what I end up with is something like this:

HOTEL1 12/06/2020 08:46 4,200

HOTEL2 12/06/2020 07:38 468

 

instead, I want:

HOTEL1 12/06/2020 08:46 22

HOTEL2 12/06/2020 07:38 5

 

It's like its aggregating the room value for some reason. I'm losing my hair with this one. Please save my hair

1 ACCEPTED SOLUTION

Hi @cyberblitz ,

 

Based on your sample, I got the following result. Is it your expected output?

2-1.PNG 

Here are two measures I used.

Max Date =
CALCULATE (
    MAX ( 'Table'[ModifiedAt] ),
    ALLEXCEPT ( 'Table', 'Table'[Facility] )
)
Value =
CALCULATE (
    MAX ( 'Table'[Beds] ),
    FILTER ( 'Table', 'Table'[ModifiedAt] = [Max Date] )
)

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

16 REPLIES 16
harshnathani
Community Champion
Community Champion

Hi @cyberblitz ,

 

 

Check if your data types in Power Query is correct.

 

 

1.jpg

 

 

Regards,
Harsh Nathani

Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

@harshnathani 

Thanks. The datatypes are set correctly and still it doesn't work

Hi @cyberblitz ,

 

What is the logic of the expected output.

 

8:46 is for 3 columns related to Hotel 1.

 

Can you share the logic.

 

Regards,

Harsh Nathani

@harshnathani 

The logic would be to have the MAX value from those from the same time

Hi @cyberblitz ,

 

 

Create a measure

 

MAxim = MAXX(SUMMARIZE('Table','Table'[ModifiedAt],'Table'[Rooms]),'Table'[Rooms])
 
 
1.jpg
 
 
Regards,
Harsh Nathani
 
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button

I don't know why, but this is what I get.

cyberblitz_2-1592912491067.png

In SQL, this is how I would do it:

 

select a.Facility, modif, rooms
from table a
inner join (
select Facility, max(modifiedAt) modif
from table
group by Facility
) b on a.Facility = b.Facility and a.ModifiedAt = b.modif

 

 

 

 

amitchandak
Super User
Super User

@cyberblitz , refer if one of these can work

summarize(Table,table[Facility],LASTNONBLANKVALUE(Table[ModifiedAt],max(table[Rooms])))

or
summarize(Table,table[Facility],LASTNONBLANKVALUE(Table[ModifiedAt],LASTNONBLANKVALUE(Table[Shift],max(table[Rooms]))))

or
summarize(Table,table[Facility],LASTNONBLANKVALUE(Table[ModifiedAt],FIRSTNONBLANKVALUE(Table[Shift],max(table[Rooms]))))

@amitchandak

I am afraid not. I get the error: Function SUMMARIZE expects a column name as argument number 4.

When i insert a column name in, i get the error: The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

@cyberblitz , Try like

sumx(summarize(Table,table[Facility],"_1",LASTNONBLANKVALUE(Table[ModifiedAt],max(table[Rooms]))),[_1])
sumx(summarize(Table,table[Facility],"_1",LASTNONBLANKVALUE(Table[ModifiedAt],LASTNONBLANKVALUE(Table[Shift],max(table[Rooms])))) ,[_1])
sumx(summarize(Table,table[Facility],"_1",LASTNONBLANKVALUE(Table[ModifiedAt],FIRSTNONBLANKVALUE(Table[Shift],max(table[Rooms])))) ,[_1])

@amitchandak 

 

I'm afraid this does not work either.

 

What i get is:

HOTEL1 12/06/2020 08:46 4,200

HOTEL2 12/06/2020 07:38 468

 

instead, I want this:

HOTEL1 12/06/2020 08:46 22

HOTEL2 12/06/2020 07:38 5

 

 

Everytime i apply these formulas, the value i need singled out is been aggreagated. This is so simple to do in SQL, why is so difficult using DAX??

 

 

 

@cyberblitz , provide data in table format. From excel copy paste on the word and from word to browser. Or upload excel dropbox or onedrive

Hi @cyberblitz ,

 

Based on your sample, I got the following result. Is it your expected output?

2-1.PNG 

Here are two measures I used.

Max Date =
CALCULATE (
    MAX ( 'Table'[ModifiedAt] ),
    ALLEXCEPT ( 'Table', 'Table'[Facility] )
)
Value =
CALCULATE (
    MAX ( 'Table'[Beds] ),
    FILTER ( 'Table', 'Table'[ModifiedAt] = [Max Date] )
)

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

@v-eachen-msft 

 

Yep, that's it. Many Thanks. I suppose it's similiar to the SQL script i created to produce the same result, where it refers upon itself..

@v-eachen-msft

 

No, sorry.

 

The result should look exactly like:

FACILITY     MAX DATE                     VALUE

HOTEL1     12/06/2020 08:46:17      22

HOTEL2     12/06/2020 07:38:39      5

Hi @cyberblitz ,

 

Sorry, I forgot to use a date type. 

Here is the result:

3-2.PNG

The measures are the two measures above.

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

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.