Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
yuvalpi
Regular Visitor

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!

2 ACCEPTED SOLUTIONS
SpartaBI
Community Champion
Community 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

 

SpartaBI_0-1656510342932.png

 




2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

View solution in original post

SpartaBI
Community Champion
Community Champion

@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

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

View solution in original post

10 REPLIES 10
yuvalpi
Regular Visitor

@SpartaBI 

 

WOW - that's exactly what I needed.

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

SpartaBI
Community Champion
Community Champion

@yuvalpi my pleasure 🙂 Will appreciate your kudos :))
Hey, check out my showcase report - got some high level stuff there. Sure you will find there a lot of cool ideas. 
https://community.powerbi.com/t5/Data-Stories-Gallery/SpartaBI-Feat-Contoso-100K/td-p/2449543
Give it a thumbs up over there if you liked it 🙂

SpartaBI
Community Champion
Community 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

 

SpartaBI_0-1656490387803.png


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

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

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
Community Champion
Community 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

 

SpartaBI_0-1656510342932.png

 




2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Hi again,

I have a followup question.

How can I ingore blanks in the Release column? e.g. for this table to count only the rel1 and rel3, but not the blank value as an item.

 

keydescriptionreleaseunique
111item for salerel12
111item for salerel12
111item for sale 2
111item for sale 2
111item missingrel32

 

thanks again,

@yuvalpi 

SpartaBI
Community Champion
Community Champion

@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

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Yes, exactly!

thank you much, again!

 

@yuvalpi 

SpartaBI
Community Champion
Community Champion

SpartaBI
Community Champion
Community Champion

@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

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png


Full-Logo11.png

SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Showcase Report – Contoso By SpartaBI

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.