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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
kinkate18nic
Frequent Visitor

Count unique values present across months

Hello,

I have data set similar to below:

Event DateAlertID
1/20/202364hytv57684
1/20/202364hytv57684
2/20/2023hf6474jdd6
2/20/2023hyalam90yd
2/20/2023hyalam90yd
3/20/2023njs7109jdd6
4/20/2023njs7109jdd6
4/20/2023axm86djdkf
4/20/2023axm86djdkf

I want to count unique alertIDs month wise.

the measure : UniqueAlertIDCount = DISTINCTCOUNT('TableName'[AlertID])
counts alertID twice if its present in two months, in this case "njs7109jdd6" is present in both March and April, the out put i want is 

Month Unique AlertID Count

January1
February2
March1
April1

However alerting and modify measures, I still get: April as 2

1 ACCEPTED SOLUTION

@kinkate18nic 
Yes, it will be counted as 1. But you can filter it out using either of the folowing depending on whether the blank is acually BLANK () or just empty string ""

Unique AlertID Count =
VAR CurrentDate =
    MIN ( 'Table'[Event Date] )
VAR CurrentIDs =
    FILTER ( VALUES ( 'Table'[AlertID] ), 'Table'[AlertID] <> BLANK () )
VAR PreviousIDs =
    DISTINCT (
        SELECTCOLUMNS (
            FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Event Date] < CurrentDate ),
            "AlertID", 'Table'[AlertID]
        )
    )
RETURN
    COUNTROWS ( EXCEPT ( CurrentIDs, PreviousIDs ) )


Unique AlertID Count =
VAR CurrentDate =
    MIN ( 'Table'[Event Date] )
VAR CurrentIDs =
    FILTER ( VALUES ( 'Table'[AlertID] ), 'Table'[AlertID] <> "" )
VAR PreviousIDs =
    DISTINCT (
        SELECTCOLUMNS (
            FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Event Date] < CurrentDate ),
            "AlertID", 'Table'[AlertID]
        )
    )
RETURN
    COUNTROWS ( EXCEPT ( CurrentIDs, PreviousIDs ) )

 

 

View solution in original post

4 REPLIES 4
tamerj1
Super User
Super User

Hi @kinkate18nic 

Please try

Unique AlertID Count =
VAR CurrentDate =
MIN ( 'Table'[Event Date] )
VAR CurrentIDs =
VALUES ( 'Table'[AlertID] )
VAR PreviousIDs =
DISTINCT (
SELECTCOLUMNS (
FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Event Date] < CurrentDate ),
"AlertID", 'Table'[AlertID]
)
)
RETURN
COUNTROWS ( EXCEPT ( CurrentIDs, PreviousIDs ) )

Thank for the measure, this seems to be working fine. Just a hiccup, suppose if there is a blank alertID in a month, will that cause the count of the month to increase? I was testing this out in my dataset, for march i have actual 4 unique alertids and there is one entry with eventid but alert id blank. for march this measure is providing 5 as the count.

@kinkate18nic 
Yes, it will be counted as 1. But you can filter it out using either of the folowing depending on whether the blank is acually BLANK () or just empty string ""

Unique AlertID Count =
VAR CurrentDate =
    MIN ( 'Table'[Event Date] )
VAR CurrentIDs =
    FILTER ( VALUES ( 'Table'[AlertID] ), 'Table'[AlertID] <> BLANK () )
VAR PreviousIDs =
    DISTINCT (
        SELECTCOLUMNS (
            FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Event Date] < CurrentDate ),
            "AlertID", 'Table'[AlertID]
        )
    )
RETURN
    COUNTROWS ( EXCEPT ( CurrentIDs, PreviousIDs ) )


Unique AlertID Count =
VAR CurrentDate =
    MIN ( 'Table'[Event Date] )
VAR CurrentIDs =
    FILTER ( VALUES ( 'Table'[AlertID] ), 'Table'[AlertID] <> "" )
VAR PreviousIDs =
    DISTINCT (
        SELECTCOLUMNS (
            FILTER ( ALLSELECTED ( 'Table' ), 'Table'[Event Date] < CurrentDate ),
            "AlertID", 'Table'[AlertID]
        )
    )
RETURN
    COUNTROWS ( EXCEPT ( CurrentIDs, PreviousIDs ) )

 

 

yep, works perfectly, thanks a lot for your help

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.