Forum Discussion

BIswajit_Das's avatar
BIswajit_Das
Impactful Individual
3 years ago
Solved

power bi loop

Present data

id  response

1       a        

1       b        

1       a        

2       a        

3       b        

Required Data

id  response   Maxcountbasedata

1       a               a

1       b               a

1       a               a

2       a               a

3       b               b

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi BIswajit_Das ,

    I created a sample pbix file(see the attachment), please check if that is what you want.

    1. Create a calculated column as below to get the count of per response under per id

    Count = 
    CALCULATE (
        COUNT ( 'Table'[response] ),
        FILTER (
            'Table',
            'Table'[id] = EARLIER ( 'Table'[id] )
                && 'Table'[response] = EARLIER ( 'Table'[response] )
        )
    )

    2. Create a measure as below to get the response which have the max count

    Maxcountbasedata = 
    VAR _selid =
        SELECTEDVALUE ( 'Table'[id] )
    VAR _count =
        CALCULATE (
            MAX ( 'Table'[Count] ),
            FILTER ( ALLSELECTED ( 'Table' ), 'Table'[id] = _selid )
        )
    RETURN
        CALCULATE (
            MAX ( 'Table'[response] ),
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[id] = _selid
                    && 'Table'[Count] = _count
            )
        )

    Best Regards

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi BIswajit_Das ,

    You can create a calculated column as below to replace the measure, please find the details in the attachment.

    Column =
    VAR _count =
        CALCULATE (
            MAX ( 'Table'[Count] ),
            FILTER ( 'Table', 'Table'[id] = EARLIER ( 'Table'[id] ) )
        )
    RETURN
        CALCULATE (
            MAX ( 'Table'[response] ),
            FILTER (
                'Table',
                'Table'[id] = EARLIER ( 'Table'[id] )
                    && 'Table'[Count] = _count
            )
        )

    Best Regards

11 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi BIswajit_Das ,

    I created a sample pbix file(see the attachment), please check if that is what you want.

    1. Create a calculated column as below to get the count of per response under per id

    Count = 
    CALCULATE (
        COUNT ( 'Table'[response] ),
        FILTER (
            'Table',
            'Table'[id] = EARLIER ( 'Table'[id] )
                && 'Table'[response] = EARLIER ( 'Table'[response] )
        )
    )

    2. Create a measure as below to get the response which have the max count

    Maxcountbasedata = 
    VAR _selid =
        SELECTEDVALUE ( 'Table'[id] )
    VAR _count =
        CALCULATE (
            MAX ( 'Table'[Count] ),
            FILTER ( ALLSELECTED ( 'Table' ), 'Table'[id] = _selid )
        )
    RETURN
        CALCULATE (
            MAX ( 'Table'[response] ),
            FILTER (
                ALLSELECTED ( 'Table' ),
                'Table'[id] = _selid
                    && 'Table'[Count] = _count
            )
        )

    Best Regards

    • BIswajit_Das's avatar
      BIswajit_Das
      Impactful Individual

      Thanks a lot It's really helpful

      But i need the measure value in a column to use it on the shape map

      Is there any way to so

       

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi BIswajit_Das ,

      You can create a calculated column as below to replace the measure, please find the details in the attachment.

      Column =
      VAR _count =
          CALCULATE (
              MAX ( 'Table'[Count] ),
              FILTER ( 'Table', 'Table'[id] = EARLIER ( 'Table'[id] ) )
          )
      RETURN
          CALCULATE (
              MAX ( 'Table'[response] ),
              FILTER (
                  'Table',
                  'Table'[id] = EARLIER ( 'Table'[id] )
                      && 'Table'[Count] = _count
              )
          )

      Best Regards