Forum Discussion

snehasissamal's avatar
snehasissamal
Frequent Visitor
2 years ago
Solved

Create multiple rows against unique Tasks using DAX

Hi,

I have a table with different tasks as follows , I want to create 3 records for each task to track the efforts against 3 values(Estimated, Spent & Remaining) as follows. Any help to dynamically get the data using DAX in desired format is much appreaciated.

 

Original Table

Task IDTitleTask StatusAssignedToEstimatedHoursCompletedHours
1Task AOpenTom8

0

 

2Task BIn ProressDavid2410
3Task COpenRaj300
4Task DClosedTom1010
5Task EOpenDavid120

 

Status

 

EffortStatus
Assgined
Spent
Remaining

 

Need data in below format,

   

Task IDTitleTask StatusAssignedToEffortStatusHours
1Task AOpenTomAssgined8
1Task AOpenTomSpent0
1Task AOpenTomRemaining8
2Task BIn ProressDavidAssgined24
2Task BIn ProressDavidSpent10
2Task BIn ProressDavidRemaining14

 

Probably I have to create 3 rows with new column as " EffortStatus" first, and then loop and based on the "EffortStatus" value, I have to calculate the hours.

 

  • Hi,

    I am not sure if I understood your question correctly, but I tried to creat a table like below.

    Please check the below picture and the attached pbix file.

    It is for creating a new table.

     

     

     

    expected result table = 
    VAR _t =
        SUMMARIZE (
            'Original Table',
            'Original Table'[Task ID],
            'Original Table'[Title],
            'Original Table'[Task Status],
            'Original Table'[AssignedTo]
        )
    VAR _effortstatus = 'Status'
    VAR _result =
        GENERATE ( _t, _effortstatus )
    RETURN
        ADDCOLUMNS (
            _result,
            "Hours",
                SWITCH (
                    TRUE (),
                    'Status'[EffortStatus] = "Assgined",
                        SUMX (
                            FILTER (
                                'Original Table',
                                'Original Table'[Task ID] = EARLIER ( 'Original Table'[Task ID] )
                            ),
                            'Original Table'[EstimatedHours]
                        ),
                    'Status'[EffortStatus] = "Spent",
                        SUMX (
                            FILTER (
                                'Original Table',
                                'Original Table'[Task ID] = EARLIER ( 'Original Table'[Task ID] )
                            ),
                            'Original Table'[CompletedHours]
                        ),
                    SUMX (
                        FILTER (
                            'Original Table',
                            'Original Table'[Task ID] = EARLIER ( 'Original Table'[Task ID] )
                        ),
                        'Original Table'[EstimatedHours] - 'Original Table'[CompletedHours]
                    )
                )
        )

2 Replies

  • Hi,

    I am not sure if I understood your question correctly, but I tried to creat a table like below.

    Please check the below picture and the attached pbix file.

    It is for creating a new table.

     

     

     

    expected result table = 
    VAR _t =
        SUMMARIZE (
            'Original Table',
            'Original Table'[Task ID],
            'Original Table'[Title],
            'Original Table'[Task Status],
            'Original Table'[AssignedTo]
        )
    VAR _effortstatus = 'Status'
    VAR _result =
        GENERATE ( _t, _effortstatus )
    RETURN
        ADDCOLUMNS (
            _result,
            "Hours",
                SWITCH (
                    TRUE (),
                    'Status'[EffortStatus] = "Assgined",
                        SUMX (
                            FILTER (
                                'Original Table',
                                'Original Table'[Task ID] = EARLIER ( 'Original Table'[Task ID] )
                            ),
                            'Original Table'[EstimatedHours]
                        ),
                    'Status'[EffortStatus] = "Spent",
                        SUMX (
                            FILTER (
                                'Original Table',
                                'Original Table'[Task ID] = EARLIER ( 'Original Table'[Task ID] )
                            ),
                            'Original Table'[CompletedHours]
                        ),
                    SUMX (
                        FILTER (
                            'Original Table',
                            'Original Table'[Task ID] = EARLIER ( 'Original Table'[Task ID] )
                        ),
                        'Original Table'[EstimatedHours] - 'Original Table'[CompletedHours]
                    )
                )
        )
  • snehasissamal's avatar
    snehasissamal
    Frequent Visitor

    Hi Jihwan_Kim ,

     

    Thank you so much it worked as expected &  have marked as accepted answer so that it may help opthers.

     

    I was looking at the output, for different Tasks, Status column values are in dfferent order. For Example. for Task A, Status values are (Spent, Assigned, Remaining) while for TaskB, its (Assigned, Spent, Remaining) as in the picture. 

     

    Can we sort it or keep it in same order?