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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
db121
Regular Visitor

Fetching the last status from a related table with 1:N relationship

Hi,
I have a ticketing system build on Sharepoint and reporting via PowerBI. I have two tables viz. "Ticket" and "Ticket_Status". The table "Ticket_Status" stores the day to day progress against each ticket. I need to show the last status against each ticket in the "Ticket" table which is fetched from "Ticket_Status". Refer the sample data below:-

PowerBI_Table_post1.PNG

 

Relationship
Ticket[ID] 1 * Ticket_Status[RefID]

Ticket[ID] (One) --> Ticket_Status[RefID] (many)

 

I would like to create a new column in table "Ticket" named "CurrentStatus" which should fetch the values from the field "Status" in the table "Ticket_Status" based on the maximum available "Date" value.

 

PowerBI_Table_post2.PNG

 

The RELATED function doesn`t seem to work as the relationship is the otherway round hence I have tried the LOOKUPVALUE function but with error. My formula for 'Ticket'[CurrentStatus] is as follows:- LOOKUPVALUE('Ticket_Status'[Status],'Ticket_Status'[RefID],'Ticket'[Id],'Ticket_Status'[Date],MAXA('Ticket_Status'[Date]))

 

The error is:- Function 'LOOKUPVALUE' does not support comparing values of type Text with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.

 

Whats wrong with my formula? Is there a better way to get it done apart from the LOOKUPVALUE function?

Thanks for any help.

 

Regards,

Deb

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@db121,

 

Try this calculated column in table Ticket:

 

CurrentStatus = 
VAR vMaxDate =
    CALCULATE ( MAX ( Ticket_Status[Date] ), RELATEDTABLE ( Ticket_Status ) )
VAR vResult =
    CALCULATE ( MAX ( Ticket_Status[Status] ), Ticket_Status[Date] = vMaxDate )
RETURN
    vResult

 

DataInsights_0-1631194303518.png

 





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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
db121
Regular Visitor

Thank you @DataInsights  the solution worked like a charm.

DataInsights
Super User
Super User

@db121,

 

Try this calculated column in table Ticket:

 

CurrentStatus = 
VAR vMaxDate =
    CALCULATE ( MAX ( Ticket_Status[Date] ), RELATEDTABLE ( Ticket_Status ) )
VAR vResult =
    CALCULATE ( MAX ( Ticket_Status[Status] ), Ticket_Status[Date] = vMaxDate )
RETURN
    vResult

 

DataInsights_0-1631194303518.png

 





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

Proud to be a Super User!




Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.