Forum Discussion

TomSinAA's avatar
TomSinAA
Icon for Helper IV rankHelper IV
3 years ago
Solved

measure to group values

Is it possible to create measures that display the unique value for a column in a table that has multiple repeating rows with the same values in the column and the measure uses another column to group by.

 

If the data looks like this: 

StateColorIDPKDescriptionA PtsB PtsMade Pts
ReadyYellow3ABX-45Walking732
ReadyYellow3ABX-45Walking731
ReadyYellow3ABX-45Walking73NULL
ReadyYellow3ABX-45Walking73NULL
ReadyYellow3ABX-45Walking73NULL
ReadyBlue3ABX-46Running94NULL
ReadyBlue3ABX-46Running94NULL
ReadyBlue3ABX-46Running941
ReadyBlue3ABX-46Running94NULL
ReadyBlue3ABX-46Running94NULL

 

 

I want to be able create a measure for A pts and B pts columns that display the data like this:

StateColorIDPKDescriptionA PtsB PtsMade Pts
ReadyYellow3ABX-45Walking733
ReadyBlue3ABX-46Running941

 

So A pts and B pts columns are grouped by Description when rolled up into the summary table, but Made Pts column sums the total by Description.

 

Then another table that displays the overall totals like this:

StateA PtsB PtsMade Pts
Ready1674
  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi TomSinAA 

    You can try the following mwasures

    A =
    VAR A =
        SUMMARIZE ( 'Table', [State], [Color], [PK], "a_min", MIN ( 'Table'[A Pts] ) )
    RETURN
        SUMX (
            FILTER (
                A,
                [State]
                    IN VALUES ( 'Table'[State] )
                        && [Color]
                            IN VALUES ( 'Table'[Color] )
                                && [PK] IN VALUES ( 'Table'[PK] )
            ),
            [a_min]
        )
    
    B =
    VAR A =
        SUMMARIZE ( 'Table', [State], [Color], [PK], "b_min", MIN ( 'Table'[b Pts] ) )
    RETURN
        SUMX (
            FILTER (
                A,
                [State]
                    IN VALUES ( 'Table'[State] )
                        && [Color]
                            IN VALUES ( 'Table'[Color] )
                                && [PK] IN VALUES ( 'Table'[PK] )
            ),
            [b_min]
        )
    
    Mode =
    VAR A =
        ADDCOLUMNS (
            'Table',
            "Mode", IF ( [Made Pts] <> "NULL", INT ( [Made Pts] ), 0 )
        )
    VAR b =
        SUMMARIZE (
            A,
            [State],
            [Color],
            [PK],
            "Sum",
                SUMX (
                    FILTER (
                        a,
                        [State]
                            IN VALUES ( 'Table'[State] )
                                && [Color]
                                    IN VALUES ( 'Table'[Color] )
                                        && [PK] IN VALUES ( 'Table'[PK] )
                    ),
                    [Mode]
                )
        )
    RETURN
        SUMX (
            FILTER (
                b,
                [State]
                    IN VALUES ( 'Table'[State] )
                        && [Color]
                            IN VALUES ( 'Table'[Color] )
                                && [PK] IN VALUES ( 'Table'[PK] )
            ),
            [Sum]
        )
    

     

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

9 Replies

  • Hi,

    Drag the first 4 columns to a Table visual and write these measures

    M1 = min(Data[A Pts])

    M2 = min(Data[B Pts])

    M3 = sum(Data[Made Pts])

    Hope this helps.

    • TomSinAA's avatar
      TomSinAA
      Icon for Helper IV rankHelper IV

      That works for the body of the first visual titled: Summary by State, ID, Color, Description.  But the total at the bottom is not correct.  It should be 16 for A pts and 7 for B Pts.  It does not work for the Summary by State visual.

       

       

        

       

       

      • TomSinAA's avatar
        TomSinAA
        Icon for Helper IV rankHelper IV

        Ok, here is a visual using the same structured data.  

         

        I am using this measure as the:

        1.ReqBoardEpicEstReqPts = CONVERT(CALCULATE(Max('pbi Issue'[ReqBoardEpicEstimatedRequirementsPoints]),FILTER('pbi Issue',ISBLANK([IssueEpicLink])=True)),INTEGER)
         
        Why is the Mini Epic rown and grand Total diplaying as 50.  I want them to add the values for the individual Req rows. 
  • TomSinAA try something like this:

     

     

    M1 = SUMX ( YourTable, CALCULATE ( min(Data[A Pts] ) ) )
    

     

    • TomSinAA's avatar
      TomSinAA
      Icon for Helper IV rankHelper IV

      That did not work.  It still shows 80

       

       

  • TomSinAA I think you need this measure , you can replicate it for others as well:

     

    Measure A Pts = 
    SUMX ( 
        SUMMARIZE ( 
            MyTable, 
            MyTable[State], 
            MyTable[Color], 
            MyTable[ID], 
            MyTable[PK], 
            MyTable[Description], 
            "@Min", MIN ( MyTable[A Pts] ) 
        ), 
        [@Min] 
    )
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi TomSinAA 

    You can try the following mwasures

    A =
    VAR A =
        SUMMARIZE ( 'Table', [State], [Color], [PK], "a_min", MIN ( 'Table'[A Pts] ) )
    RETURN
        SUMX (
            FILTER (
                A,
                [State]
                    IN VALUES ( 'Table'[State] )
                        && [Color]
                            IN VALUES ( 'Table'[Color] )
                                && [PK] IN VALUES ( 'Table'[PK] )
            ),
            [a_min]
        )
    
    B =
    VAR A =
        SUMMARIZE ( 'Table', [State], [Color], [PK], "b_min", MIN ( 'Table'[b Pts] ) )
    RETURN
        SUMX (
            FILTER (
                A,
                [State]
                    IN VALUES ( 'Table'[State] )
                        && [Color]
                            IN VALUES ( 'Table'[Color] )
                                && [PK] IN VALUES ( 'Table'[PK] )
            ),
            [b_min]
        )
    
    Mode =
    VAR A =
        ADDCOLUMNS (
            'Table',
            "Mode", IF ( [Made Pts] <> "NULL", INT ( [Made Pts] ), 0 )
        )
    VAR b =
        SUMMARIZE (
            A,
            [State],
            [Color],
            [PK],
            "Sum",
                SUMX (
                    FILTER (
                        a,
                        [State]
                            IN VALUES ( 'Table'[State] )
                                && [Color]
                                    IN VALUES ( 'Table'[Color] )
                                        && [PK] IN VALUES ( 'Table'[PK] )
                    ),
                    [Mode]
                )
        )
    RETURN
        SUMX (
            FILTER (
                b,
                [State]
                    IN VALUES ( 'Table'[State] )
                        && [Color]
                            IN VALUES ( 'Table'[Color] )
                                && [PK] IN VALUES ( 'Table'[PK] )
            ),
            [Sum]
        )
    

     

    Best Regards!

    Yolo Zhu

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.