MAXROW() not returning key

I am using MAXROW to return the last record added to a child table but with an expression included:

MAXROW(โ€œCurrentโ€, โ€œ_ROWNUMBERโ€, ([_THISROW].[Key] = [Member]))

โ€œCurrentโ€ is actually a slice of a table called History because I needed to conditions two my expression and I got the same result when trying that so I added a slice. Ideally my expression would be this:

MAXROW(โ€œHistoryโ€, โ€œ_ROWNUMBERโ€, (AND([_THISROW].[Key] = [Member],โ€œCurrentโ€ = [_Filter]))

I have a Members table and for each Member I have a history of status changes in a History table. The data in my History Tables is as follows:

_RowNumber Key Member Status Section _Filter
[Number] [Text] [Ref] [Ref] [Ref] [Text]
2 8cc13f6a 284bc465 I d3be1b10 Future
3 9a8847f9 284bc465 I be46f2a0 Future
4 76fc95db 284bc465 O be46f2a0 Future
5 d2685b57 284bc465 S be46f2a0 Current
6 38927c8f 284bc465 O eef91aea Future
7 3032901f 7d792ad5 S d3be1b10 Current
8 a3a3487a 7d792ad5 S be46f2a0 Current
9 b9146e21 7d792ad5 O eef91aea Future

In testing, I am returned the value โ€œ7d792ad5โ€ which matches the Key of the member and not โ€œa3a3487aโ€ which is the key of the row in History table.

I was hoping actually that I would get the value โ€œStartedโ€ but if I have the row key I can then do a LOOKUP to get the full text string.

Any thoughts?

Solved Solved
0 17 448
1 ACCEPTED SOLUTION

This worked:

LOOKUP(MAXROW(โ€œCurrentโ€, โ€œ_ROWNUMBERโ€, ([_THISROW].[Key] = [Member])),โ€œHistoryโ€,โ€œKeyโ€,โ€œStatusโ€)

I suspect I could now get rid of my slice but after many hours on this, I will stick for now. Perhaps tomorrow I will re-insert the AND()

Many thanks for the help - very much appreciated

View solution in original post

17 REPLIES 17

So you have this expression in Members table or History table?

In the Members table

_RowNumber Number
Key Text
Name Name
Status Ref = MAXROW(โ€œCurrentโ€, โ€œ_ROWNUMBERโ€, ([_THISROW].[Key] = [Member]))

So Member table is the parent and the History table is the child, correct?

Steve
Platinum 4
Platinum 4

Huh?

Shouldda figured this out. Adding the extra slice just complicates things.

This notation is confusing: youโ€™ve put brackets around column types rather than around column names.

Not possible if you used the expressions above.

The value Started doesnโ€™t occur in your data set.

Yes Member is the Parent and History is the Child.

Sorry Steve, when I pasted my data it is was nicely formatted by all my spaces got removed. Here is the data structure of Member and History as screenshots

3X_a_a_aa221acdc5d644c5ae410f64990303817c965376.png

And the data in History as a screenshot

3X_b_f_bf34369a3bc0b712aaa0de41b8e95313cb4aae4e.png

Possible you confused the label for the key?

3X_e_7_e7a5d439a081b37f1145ad368258091d551d9d45.png

@Steve
He has the same column in the History table as well which is a ref to Members table. Thatโ€™s why he is referring to it via [_THISROW].[Key] = [Member] in his MAXROW expression.

However, as History is a child table to Members, he should have a [Related Historys] Virtual Column in the Members table. So I believe he can retrieve the value querying that column easily, right?

Ah, I see where youโ€™re going now. Yeah, that should be possible, Iโ€™d think.

Just to confirm, yes I have the [Related Historys] Virtual Column in the Members table

So below expression might work

ANY(
	SELECT(
		[Related Historys][Your_Query_Column],
		[_RowNumber]= MAX([Related Historys][_RowNumber])
	)
)

I changed [Your_Query_Column] for [Status] as that is what I want to retrieve and that returns nothing. However the challenge I have is that I want the last entered status for that Member but only if _Filter is set to Current. The query you have, given my dataset should have returned the very last row for the member but the _FIlter is set to Future on that row.

I guess I could create a virtual column that is a join of the member and the Filter and then look for that instead? Would that work? Seems messy butโ€ฆ

Very messy. Or you could just use AND().

Steve is correct. The label is what is being returned. Changing that makes my original query work

ANY(
	SELECT(
		[Related Historys][Your_Query_Column],
		[_RowNumber]= MAX([RelatedHistorys][_RowNumber],"Current" = [_Filter])
	)
)

Sorry Levent, I get โ€œMAX function is used incorrectlyโ€

This worked:

LOOKUP(MAXROW(โ€œCurrentโ€, โ€œ_ROWNUMBERโ€, ([_THISROW].[Key] = [Member])),โ€œHistoryโ€,โ€œKeyโ€,โ€œStatusโ€)

I suspect I could now get rid of my slice but after many hours on this, I will stick for now. Perhaps tomorrow I will re-insert the AND()

Many thanks for the help - very much appreciated

Excellent. Glad to hear that you figured it out.

Top Labels in this Space