Forum Discussion

ssharm43's avatar
ssharm43
Helper I
6 years ago
Solved

count distinct Id from unique record

Hi, I have a porblem where I have to count distinct ID's with certain conditions. I have dataset like :   Customer ID Case Name Flag 1 a yes 1 b yes 1 c no 2 a yes 2 ...
  • dm-p's avatar
    6 years ago

    Hi ssharm43, and welcome aboard!

    Based on my understanding of your question, I've provided a solution below for you.

    Just as a heads-up for further learning, you'd be better posting this kind of question in either the Desktop or DAX forums in future, as the Developer forum is concerned with extending Power BI capabilities via software development tools and techniques. A lot more users frequent the other two forums and typically don't look in here very much. DAX posts in here can sometimes take a little while to get answered.

    I have replicated your data into my workbook and called the table Data, so this will be reffered to in the measure I have written for you below.

    It does not look exactly as your output table (with the blanks), because I personally think that if you filter rows out of a table or visual then this still needs to work correctly for any rows that remain.

    Here's the output with a table with all columns (left), and for one where I take out the Case Name column (middle), and then finally the Flag (right):

    Note that in each case, even though the Distinct Count ID measure is always 1, the total is 4 for both tables, because the measure is grouping by Customer ID and Flag each time.

    The measure is as follows:

    Distinct Count ID = 
        VAR _Groups = SUMMARIZE(
            Data,
            Data[Customer ID],
            Data[Flag]
        )
        RETURN
            COUNTROWS(_Groups)

    Good luck!

    Daniel


    If my post solves your challenge, then please consider accepting as a solution to help other forum members find the answer more quickly 🙂