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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
JPOso
Frequent Visitor

Returning a cell in a row where row is the last true in an order of steps

Hi PowerBI community!

 

I just recently registered to the community and am a newbie at powerBI, I would be ever so grateful for the community's help on this. I work in clinical trials and R&D for my trust and am currently doing this project for my workplace and apprenticeship but have been stuck in trying to find a solution (online, self experimentation on powerBI, etc).

 

So what I want to achieve is to return the comments cell on a row that is the last 'True', the challenge is there are a set of steps in the 'Order' column that are recurring (1-16) this repeats for each different trial. I've also set an index column to not lose the order of each trial if sorted. I have tried experimenting with similar solutions I've come across here but I can't get them to work.

 

What I want the end user to achieve is when they click on a specific trial(in the visual solution) it should return the last comment entered which is on the same row as the last 'True' cell.

 

I hope I am not overcomplicating this. Thank you once a gain for your help.

 

Edit:

usable format

Project Short TitleOrderTaskQuestionIs CompletedDate CompletedCommentsIndex
Trial11Date site selected00 When was the site selected?TRUE04/09/2024comment1
Trial12Review Principal Investigator (PI) assigned07 Who is the PI?TRUE04/09/2024comment2
Trial13Expression of interest (EOI)07 Has the Expression Of Interest been filled and submittedTRUE04/09/2024comment3
Trial14Request information pack07 Has the Local Information Pack been requested?TRUE25/09/2024comment4
Trial15Put on R&D committee agenda14 Has this been put on the agenda?
Has the PI been invited?
TRUE15/09/2024comment5
Trial16review of Local Information Pack (LIP)14 Review of feasibility to open the studyTRUE25/02/2025comment6
Trial17Feasibility meeting14 Is the PI/ research coordinator happy with the protocol and support?
review eligibility criteria and end of recruitment date.
How many people with eligible criteria do they see? Where do they What is their target recruitment?
TRUE25/02/2025comment7
Trial18recruitment target setting14 What is the recruitment targetTRUE18/10/2024comment8
Trial19review of costings for the study14 What are the procedures that need to be done, are they standard of care?TRUE25/02/2025comment9
Trial110Complete Organisational Information Document (OID) / contracting documents14 Complete OID putting in the information for the Trust, finance and PITRUE26/02/2025comment10
Trial111Pharmacy review14 Is pharmacy involved?TRUE04/09/2024comment11
Trial112Pathology support14 Is there a research cost with pathology?TRUE04/09/2024comment12
Trial113Radiology review14 Does the study need radiology support?TRUE04/09/2024comment13
Trial114Has an SIV been organised?30 Has a SIV been organised?FALSE  14
Trial115Issue Capability & Capacity for the study35 Issue C&CFALSE  15
Trial116Trial site issues Green light to start recruitment40 Has the trial site issued a green lightFALSE  16
Trial21Date site selected00 When was the site selected?TRUE29/07/2024comment17
Trial22Review Principal Investigator (PI) assigned07 Who is the PI?TRUE29/07/2024comment18
Trial23Expression of interest (EOI)07 Has the Expression Of Interest been filled and submittedTRUE03/12/2024comment19
Trial24Request information pack07 Has the Local Information Pack been requested?TRUE23/12/2024comment20
Trial25Put on R&D committee agenda14 Has this been put on the agenda?
Has the PI been invited?
TRUE04/11/2024comment21
Trial26review of Local Information Pack (LIP)14 Review of feasibility to open the studyTRUE13/01/2025comment22
Trial27Feasibility meeting14 Is the PI/ research coordinator happy with the protocol and support?
review eligibility criteria and end of recruitment date.
How many people with eligible criteria do they see? Where do they What is their target recruitment?
FALSE  23
Trial28recruitment target setting14 What is the recruitment targetFALSE  24
Trial29review of costings for the study14 What are the procedures that need to be done, are they standard of care?TRUE15/01/2025comment25
Trial210Complete Organisational Information Document (OID) / contracting documents14 Complete OID putting in the information for the Trust, finance and PIFALSE  26
Trial211Pharmacy review14 Is pharmacy involved?TRUE29/07/2024comment27
Trial212Pathology support14 Is there a research cost with pathology?TRUE27/07/2024comment28
Trial213Radiology review14 Does the study need radiology support?TRUE29/07/2024comment29
Trial214Has an SIV been organised?30 Has a SIV been organised?FALSE  30
Trial215Issue Capability & Capacity for the study35 Issue C&CFALSE  31
Trial216Trial site issues Green light to start recruitment40 Has the trial site issued a green lightFALSE  32

2 ACCEPTED SOLUTIONS
jgeddes
Super User
Super User

A measure like the following could work for you. 
Replace the 'Table' with your table name.

Measure = 
//filter table to only include 'TRUE' Is Completed
var _vTable = 
FILTER('Table', 'Table'[Is Completed] = TRUE())
//get the max order from the filtered 'True' table
var _maxOrder = 
MAXX(_vTable, [Order])
//return the comment where the Order value equals the maxOrder value.
var _result =
MAXX(FILTER(_vTable, [Order] = _maxOrder), [Comments])
RETURN
_result




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

MasonMA
Solution Sage
Solution Sage

Hi @JPOso 

 

One of the solutions i tried is create one Column with DAX below. This returns the Last Comment in the right row context. 

LastCompletedComment = 
VAR _trial = 'Table'[Project Short Title]
VAR _maxIndex = 
    CALCULATE(
        MAX('Table'[Index]),
        FILTER(
            'Table',
            'Table'[Project Short Title] = _trial &&
            'Table'[Is Completed] = "TRUE"
        )
    )
RETURN
    IF (
        'Table'[Index] = _maxIndex &&
        'Table'[Is Completed] = "TRUE",
        'Table'[Comments],
        BLANK()
    )

 

MasonMA_0-1752769193929.png

and then in reporting, add this colunm in the report and filter out the 'Blank' rows in report

MasonMA_1-1752769271741.png

 

View solution in original post

11 REPLIES 11
v-tsaipranay
Community Support
Community Support

Hi @JPOso ,

Thank you for reaching out to the Microsoft Fabric Community Forum. Also thank you @jgeddes and @MasonMA and @FBergamaschi actively providing solutions.

 

I wanted to check if you had the opportunity to review the information provided by @MasonMA and @jgeddes. I hope that could resolve your issue. Please feel free to contact us if you have any further questions.

 

Thank you.

Hi v-tsaipranay,

 

Thank you for the kind welcome.

 

The responses are promising but unfortunately can not test them out fully as I am away on leave. Please leave this open until I get to test the responses out. Thank you!

MasonMA
Solution Sage
Solution Sage

Hi @JPOso 

 

One of the solutions i tried is create one Column with DAX below. This returns the Last Comment in the right row context. 

LastCompletedComment = 
VAR _trial = 'Table'[Project Short Title]
VAR _maxIndex = 
    CALCULATE(
        MAX('Table'[Index]),
        FILTER(
            'Table',
            'Table'[Project Short Title] = _trial &&
            'Table'[Is Completed] = "TRUE"
        )
    )
RETURN
    IF (
        'Table'[Index] = _maxIndex &&
        'Table'[Is Completed] = "TRUE",
        'Table'[Comments],
        BLANK()
    )

 

MasonMA_0-1752769193929.png

and then in reporting, add this colunm in the report and filter out the 'Blank' rows in report

MasonMA_1-1752769271741.png

 

JPOso
Frequent Visitor

Hi MasonMA,

 

Thank you for your reply, and sorry for the late response. I'm replying out of the office right now and quickly tested this out at home as I'm currently on annual. 

It seems to work but it flags out an error saying it won't accept true/false and text values. Sorry I have limited access to test this out further but I wanna test it out some more

@JPOso 

 

Hi, this would be a common data type mismatch between a Boolean type and Text type. 

The easy fix would be to update the code as below. 

'Table'[Is Completed] = TRUE()

 

Hope it works:) 

 

JPOso
Frequent Visitor

Hi MasonMA,

 

I just want to say Thank you very much for your help on this. It works! I will try to test this out extensively.

 

One concern I have is that if there is a 'False' in between the string of 'True'. It returns the last 'True' and not the 'True' before. Am I right saying there is no solution to this rather than to just clean the process that there shouldn't be a false in between the string of 'True'?

 

Once again I want to say, thank you!

Happy to see it works for you! 

 

For your question, If the business rule really is "no FALSE should appear before the last TRUE", you could also enforce this upstream in Power Query:)

jgeddes
Super User
Super User

A measure like the following could work for you. 
Replace the 'Table' with your table name.

Measure = 
//filter table to only include 'TRUE' Is Completed
var _vTable = 
FILTER('Table', 'Table'[Is Completed] = TRUE())
//get the max order from the filtered 'True' table
var _maxOrder = 
MAXX(_vTable, [Order])
//return the comment where the Order value equals the maxOrder value.
var _result =
MAXX(FILTER(_vTable, [Order] = _maxOrder), [Comments])
RETURN
_result




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





JPOso
Frequent Visitor

Hi jgeddes,

 

This works really great too! Thank you for this solution. May I pick your mind abit what are the pros and cons between just using a straight up measure than how MasonMA did it? Would it be just showing the whole working process within if someone is interested?

 

Thank you for your help!

FBergamaschi
Solution Sage
Solution Sage

Please include, in a usable format, not an image, a small set of rows for each of the tables involved in your request and show the data model in a picture, so that we can import the tables in Power BI and reproduce the data model. The subset of rows you provide, even is just a subset of the original tables, must cover your issue or question completely. Do not include sensitive information and do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided and make sure, in case you show a Power BI visual, to clarify the columns used in the grouping sections of the visual.

 

Need help uploading data? click here

 

Want faster answers? click here

Thank you, I have corrected it.

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.