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
Anonymous
Not applicable

How to obtain a last values within a column based on sequence number/ counter

Hi All,

Can someone please guide me as to how to obtain values from other columns based on the maximum value from the counter column (in this case SeqNum)?

For example: For 'LoadNum' = 347374643, I have 'SeqNum' ranging from 1 - 6, however I only require to display values from 'Destination Zip' and 'DestinationWarehouse' where 'SeqNum' = 6, i.e. 'Destination Zip' = 8491322 and 'DestinationWarehouse' = JA Beverage Sage Kashima Plant.

Similarly, for LoadNum: 347374644, I only require to display values from 'Destination Zip' and 'DestinationWarehouse', where 'SeqNum' = 2.

However, LoadNum: 347374651, has only 1 line item with SeqNum = 1, then corresponding values from other two columns needs to be displayed.

Note: 'Last Value' function works for 'SeqNum', but not for 'DestinationZip' and 'DestinationWarehouse' as numbers and alphabets won't be maximum for these columns. Values will be random in these columns.

sakshidixit_1-1616765532400.png

Thanks in advance.

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

Hi, @Anonymous 

 

According to your description, I think you can simply create a measure in filterpane to filter data.

Like this:

Measure = 
VAR a =
    MAXX (
        FILTER ( ALL ( 'Table' ), [LoadNum] = SELECTEDVALUE ( 'Table'[LoadNum] ) ),
        [Seqnum]
    )
RETURN
    IF ( MAX(  'Table'[Seqnum] ) = a, 1, 0 )

3.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

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

6 REPLIES 6
v-janeyg-msft
Community Support
Community Support

Hi, @Anonymous 

 

According to your description, I think you can simply create a measure in filterpane to filter data.

Like this:

Measure = 
VAR a =
    MAXX (
        FILTER ( ALL ( 'Table' ), [LoadNum] = SELECTEDVALUE ( 'Table'[LoadNum] ) ),
        [Seqnum]
    )
RETURN
    IF ( MAX(  'Table'[Seqnum] ) = a, 1, 0 )

3.png

If it doesn’t solve your problem, please feel free to ask me.

 

Best Regards

Janey Guo

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

Anonymous
Not applicable

Hi @Jihwan_Kim, thanks for reverting.

I tried applying the suggested formula, however doesn't seem to work.

Unable to attach the pbix file here or data file here.

Krutigawale33
Responsive Resident
Responsive Resident

Hello @Anonymous ,

 

Create the below measures

 

Seq_Num = var _max=MAX(Table[SeqNum]) return CALCULATE(MAX(Table[SeqNum]),ALLEXCEPT(Table,Table[LoadNum]),Table[SeqNum]=_max)
 
Destination_Zip = var _max=MAX(Table[SeqNum]) return CALCULATE(MAX(Table[Destination Zip]),ALLEXCEPT(Table,Table[LoadNum]),Table[SeqNum]=_max)
 
Destination_Warehouse = var _max=MAX(Table[SeqNum]) return CALCULATE(MAX(Table[DestionationWarehouse]),ALLEXCEPT(Table,Table[LoadNum]),Table[SeqNum]=_max)
 

Krutigawale33_0-1616770202813.png

 

Anonymous
Not applicable

I beleive, it's mostly because the 'MAX' function isn't working as expected in this case.

 

sakshidixit_2-1616786556484.png

 

sakshidixit_1-1616786469042.png

 

 

 

 

Anonymous
Not applicable

Hi @Krutigawale33 , thanks for reverting, however the code doesn't seem to work as expected with the data as below above in the query.

Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

Please try to create the below DAX measures.

But those still depend on the filter context. If those do not work, please kindly share the sample pbix file, then I can try to have a look and come up with a desirable solution.

 

Destination Zip =
VAR maxseqnum = MAX('DataTable'[SeqNum])
RETURN
CALCULATE( SELECTEDVALUE('DataTable'[DestinationZip]), 'DataTable'[SeqNum] = maxseqnum)
 
Destination Warehouse =
VAR maxseqnum = MAX('DataTable'[SeqNum])
RETURN
CALCULATE( SELECTEDVALUE('DataTable'[DestinationWarehouse]), 'DataTable'[SeqNum] = maxseqnum)
 
 

Jihwan Kim

If this post helps, then please consider accept it as the solution to help the other members find it more quickly.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


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.