Forum Discussion

yuvalpi's avatar
yuvalpi
Icon for Helper I rankHelper I
4 years ago
Solved

count unique record based on several columns

hi,

i have a question regarding unique records.

i have the following table:

keydescriptionrelease
111item for salerel1
111item for salerel1
111item for salerel2
111item for salerel2
111item missingrel3
2222nd itemrel1
2222nd itemrel1
2222nd itemrel1
222name changerel1
222name changerel2

 

i would like to add a row that counts the unique records accoding to column 'Key' and column 'Release'.

the outcome should be:

keydescriptionreleaseunique
111item for salerel13
111item for salerel13
111item for salerel23
111item for salerel23
111item missingrel33
2222nd itemrel12
2222nd itemrel12
2222nd itemrel12
222name changerel12
222name changerel22

 

Thanks in advance!

  • yuvalpi OKK 🙂 So I didn't understand what you meant.
    This is the column you need:

     

    Column 2 = 
    VAR _current_key = 'Table'[key]
    VAR _result = 
        CALCULATE(
            DISTINCTCOUNT( 'Table'[release] ),
            REMOVEFILTERS('Table'),
            'Table'[key] = _current_key
        )
    RETURN
        _result

     

     







          

    Showcase Report – Contoso By SpartaBI

  • yuvalpi you mean like this?:

     

    Column 2 = 
    VAR _current_key = 'Table'[key]
    VAR _result = 
        CALCULATE(
            DISTINCTCOUNT( 'Table'[release] ),
            REMOVEFILTERS('Table'),
            'Table'[key] = _current_key,
            'Table'[release] <> BLANK()
        )
    RETURN
        _result

     





          

    Showcase Report – Contoso By SpartaBI

10 Replies

  • SpartaBI 

     

    WOW - that's exactly what I needed.

    thank a lot! now I need to understand it myself... 😊

  • SpartaBI's avatar
    SpartaBI
    Icon for Community Champion rankCommunity Champion

    yuvalpi this is a column that counts the number of rows that has the same key and release:

     

    Column = 
    VAR _current_key = 'Table'[key]
    VAR _current_release = 'Table'[release]
    VAR _result = 
        COUNTROWS(
            FILTER(
                'Table',
                'Table'[key] = _current_key && 'Table'[release] = _current_release
            )
    )
    RETURN
        _result

     


    I'm not sure how you got to your result in the example, so maybe I didn't understand what you need.

     





          

    Showcase Report – Contoso By SpartaBI

    • yuvalpi's avatar
      yuvalpi
      Icon for Helper I rankHelper I

      Hi SpartaBI 

      first - thank you for the swift reply!

       

      regarding the solution, I entered into the BI, but I am not sure it is what I needed.

      per my example - I wanted to get per row the number of unique values that meet the criteria.

      in the example that I sent, if I focus only on Key 111, I can see 3 different releases (rel1, rel2, rel3), hence I wanted to show the number 3 in all the relevant rows.

      keydescriptionreleaseunique
      111item for salerel13
      111item for salerel13
      111item for salerel23
      111item for salerel23
      111item missingrel33

       

      Thank you again,

      yuvalpi 

      • SpartaBI's avatar
        SpartaBI
        Icon for Community Champion rankCommunity Champion

        yuvalpi OKK 🙂 So I didn't understand what you meant.
        This is the column you need:

         

        Column 2 = 
        VAR _current_key = 'Table'[key]
        VAR _result = 
            CALCULATE(
                DISTINCTCOUNT( 'Table'[release] ),
                REMOVEFILTERS('Table'),
                'Table'[key] = _current_key
            )
        RETURN
            _result

         

         







              

        Showcase Report – Contoso By SpartaBI