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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Etienne123
Advocate II
Advocate II

Trying to calculate the first and last value across the records in a category

Hi

 

I have a single table that looks like this.

 

Category | DateTime | Value

A | 29/11/2021 22:21:24 | $48

A | 30/11/2021 10:15:56 | $52

A | 30/11/2021 16:24:32 | $90

B | 28/11/2021 09:08:43 | $16

B | 29/11/2021 11:25:54 | $18

B | 29/11/2021 12:26:21 | $29

B | 29/11/2021 13:42:28 | $82

 

I am trying to find a DAX formula that will calculate both first and latest values for both A and B, so that it delivers something that looks like this:

 

Category | FirstValue | LatestValue

A | $48 | $90

B | $16 | $82

 

I have tried many options but none gives me what I need.

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Etienne123 

Create two measure as follows:

FirstValue = FIRSTNONBLANK(Table1[ Value] , MAX(Table1[ DateTime ] ))
LastValue = LASTNONBLANK(Table1[ Value] , MAX(Table1[ DateTime ] ))


Add them in a matrix 

Fowmy_0-1638275513860.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

2 REPLIES 2
v-eqin-msft
Community Support
Community Support

Hi @Etienne123 ,

 

You could use the following formula to create a new table:

NewTable = 
ADDCOLUMNS (
    VALUES ( 'Table'[Category] ),
    "FirstValue",
        VAR _firstdate =
            MINX ( FILTER ( 'Table', [Category] = EARLIER ( [Category] ) ), [DateTime] )
        RETURN
            LOOKUPVALUE ( 'Table'[Value], [Category], [Category], [DateTime], _firstdate ),
    "LatestValue",
        VAR _lastdate =
            MAXX ( FILTER ( 'Table', [Category] = EARLIER ( [Category] ) ), [DateTime] )
        RETURN
            LOOKUPVALUE ( 'Table'[Value], [Category], [Category], [DateTime], _lastdate )
)

 

Output:

Eyelyn9_0-1638518183485.png

 

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Fowmy
Super User
Super User

@Etienne123 

Create two measure as follows:

FirstValue = FIRSTNONBLANK(Table1[ Value] , MAX(Table1[ DateTime ] ))
LastValue = LASTNONBLANK(Table1[ Value] , MAX(Table1[ DateTime ] ))


Add them in a matrix 

Fowmy_0-1638275513860.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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