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
jthake-msft
Employee
Employee

1 to many relationship - want to show top row foreign key as column

I have a scenario where I have a table with a 1 to many relationship

 

Questions

QuestionId - Title

 

QuestionsWorkloadId

QuestionID - WorkloadId - WorkloadAssignmentDate

 

In the Questions table, I would like to have a column added to show the workloadId for the row with the most recent WorkloadAssignmentDate.

 

I was looking into using something like 

CurrentWorkloadId = CALCULATE(TOPN(1,QuestionWorkloadAssignments, QuestionWorkloadAssignments[WorkloadId], ASC))
 
But I can't seem to work out how to get it to work . Could someone help me please?
1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Hi @jthake-msft ,

 

try this:

 

MAXX(
    TOPN(
        1,

        RELATEDTABLE ( QuestionWorkloadAssignments),

        QuestionWorkloadAssignments[Date],

        ASC),
    QuestionWorkloadAssignments[workloadId] )

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

4 REPLIES 4
ImkeF
Super User
Super User

Hi @jthake-msft ,

 

try this:

 

MAXX(
    TOPN(
        1,

        RELATEDTABLE ( QuestionWorkloadAssignments),

        QuestionWorkloadAssignments[Date],

        ASC),
    QuestionWorkloadAssignments[workloadId] )

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Thank you.

 

If the Workload table had a WorkloadName

 

Is there a way to output that in the column rather than the WorkloadId?

 

As I can't seem to add a relationship to this column to a table, so that I can create a chart that shows a breakdown of number of questions by Workload name 

Hi

I might be missing something here, but wouldn' t this work?:

 

MAXX(
    TOPN(
        1,

        RELATEDTABLE ( QuestionWorkloadAssignments),

        QuestionWorkloadAssignments[Date],

        ASC),
    QuestionWorkloadAssignments[Name] )

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

No the name of the workload is in the Workload table not the QuestionWorkloadAssignments table. In the formula, it can't resolve Workload[Name], I'm guessing because it isn't the related table. Although QuestionWorkloadAssignments does have a retionship with the Workload table.

 

Questions

QuestionId - Title

 

QuestionsWorkloadAssignments

QuestionID - WorkloadId - WorkloadAssignmentDate

 

Workload

WorkloadId - WorkloadName

 

 

What I did was create a new Column basically adding WorkloadName to the QuestionsworkloadAssignments table. And then used this in the Questions table for CurrentWorkloadName column based on your formula. Thank you!

 

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.