Forum Discussion

Rajat's avatar
Rajat
Frequent Visitor
10 years ago

Retrive a value from multiple matching records

 

Project Master                                                                                         Task Allocation

 

ProjectID  projectName  Project Status                                                 Task ID   ProjectiD  Task status

  P1            A                                                                                           T1          P1           Completed

  P2            B                                                                                           T2          P1            In progress

  P3            C                                                                                           T3          P1            Completed

                                                                                                                T4          P2           Inprogress

                                                                                                                T5          P2           Completed

                                                                                                                T6          P2           In progress

 

 

I need to update "Project status" in Project Master in such a way that if any of the task of Project is in progress then we need to update "Project status"  as "In progress" othervise "Completed".

 

Can any one tell me, how to approach this problem.

 

I tried it with LookupValue(),but is works only for one matching record.But here are multiple matching record.

4 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Rajat, First, please do not cross-post in every forum, that's not cool. A lot of us use the "All Topics" view and so we see your post four times and have no idea which one to respond to.

     

    Second, try something like this:

     

    IF(COUNTAX(FILTER('Task Allocation'[Task status]='In Progress'),[Task ID]) = 0,"In progress", "Completed)

     

     

     

     

    • greggyb's avatar
      greggyb
      Resident Rockstar
      Status = 
      IF(
          ISEMPTY(
              CALCULATETABLE(
                  'Task Allocation'
                  ,'Task Allocation'[Task Status] = "In Progress"
              )
          )
          ,"Completed"
          ,"In Progress"
      )

      This assumes a relationship between 'Project Master' and 'Task Allocation'.

       

      CALCULATETABLE() will respect the row context of [Project ID] from 'Project Master' and give us the matching rows from 'Task Allocation'. Additionally, we apply a filter to return only rows where 'TaskAllocation'[Task Status] = "In Progress". We test the resulting table with ISEMPTY() which tests what it says. If there are no rows, we know the project is complete. If there are rows with "In Progress", then the project is in progress.

  • SELECT PM.ProjectID, PM.projectName,
    CASE WHEN T.ProjectID IS NULL THEN 'Completed' ELSE 'In progress' END as ProjectStatus
    FROM Project_Master PM,
    (SELECT distinct ProjectiD
    from task_allocation
    where Task_status = 'In progress') t
    WHERE pm.ProjectID = t.ProjectiD(+)