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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Dyke211
Helper I
Helper I

Want to Count Items that Appears More than Once

I have a problem. i have this column columns in my data set and i want to be able to count each object class that appears more than once within a month..I also have a different calender table and made a relationship with this  "Obj_reported".. I have tried this and sis not work


"CountObjectsOverOncePerMonth =
VAR Event_Count =
ADDCOLUMNS (
SUMMARIZE ( Data, Data[Obj_Classs], YEAR(Data[Obj_Reported]), MONTH(Data[Obj_Reported])),
"Count", CALCULATE ( COUNTROWS ( Data), ALLEXCEPT ( Data, Data[Obj_Classs], YEAR(Data[Obj_Reported]), MONTH(Data[Obj_Reported])) )
)
VAR Objects_Beyond_1 = FILTER ( Event_Count, [Count] > 1 )
RETURN
COUNTROWS ( Objects_Beyond_1 )
"

 

 

 

 

 

 

Obj_ClasssObj_Reported
A20/02/2021
A21/02/2021
B20/04/2021
C27/06/2021
G22/08/2021
B27/07/2021
B27/12/2021
G30/08/2021
D21/02/2023
E21/02/2021
A21/11/2021
G07/08/2021
G08/10/2022
  
2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1715794100387.png

 

 

Jihwan_Kim_0-1715794079240.png

 

 

More than once within the same month: =
VAR _t =
    SUMMARIZE (
        Data,
        Obj_Classs[Obj_Classs],
        'Calendar'[Year-Month sort],
        'Calendar'[Date]
    )
VAR _conditiontable =
    FILTER (
        ADDCOLUMNS (
            _t,
            "@appearancecount",
                COUNTROWS (
                    FILTER (
                        _t,
                        Obj_Classs[Obj_Classs] = EARLIER ( Obj_Classs[Obj_Classs] )
                            && 'Calendar'[Year-Month sort] = EARLIER ( 'Calendar'[Year-Month sort] )
                    )
                )
        ),
        [@appearancecount] > 1
    )
RETURN
    COUNTROWS ( SUMMARIZE ( _conditiontable, Obj_Classs[Obj_Classs] ) )

 



Microsoft MVP



If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question



View solution in original post

Anonymous
Not applicable

Hi @Dyke211 

 

Thanks for the reply from @Jihwan_Kim , please allow me to provide another insight:

Create a measure:

MEASURE =
VAR _Event_Count =
    SUMMARIZE (
        ADDCOLUMNS (
            'Data',
            "_Year_Month", FORMAT ( 'Data'[Obj_Reported], "YYYY-MM" ),
            "_Count",
                CALCULATE (
                    COUNTROWS ( 'Data' ),
                    FILTER (
                        ALL ( Data ),
                        'Data'[Obj_Classs] = EARLIER ( Data[Obj_Classs] )
                            && YEAR ( 'Data'[Obj_Reported] ) = YEAR ( EARLIER ( 'Data'[Obj_Reported] ) )
                            && MONTH ( 'Data'[Obj_Reported] ) = MONTH ( EARLIER ( Data[Obj_Reported] ) )
                    )
                )
        ),
        [Obj_Classs],
        [_Year_Month],
        [_Count]
    )
RETURN
    COUNTROWS ( FILTER ( _Event_Count, [_Count] > 1 ) )

 The result:

vzhengdxumsft_0-1715839683511.png

Or you can create a table:

Table =
FILTER (
    SUMMARIZE (
        ADDCOLUMNS (
            'Data',
            "_Year_Month", FORMAT ( 'Data'[Obj_Reported], "YYYY-MM" ),
            "_Count",
                CALCULATE (
                    COUNTROWS ( 'Data' ),
                    FILTER (
                        ALL ( Data ),
                        'Data'[Obj_Classs] = EARLIER ( Data[Obj_Classs] )
                            && YEAR ( 'Data'[Obj_Reported] ) = YEAR ( EARLIER ( 'Data'[Obj_Reported] ) )
                            && MONTH ( 'Data'[Obj_Reported] ) = MONTH ( EARLIER ( Data[Obj_Reported] ) )
                    )
                )
        ),
        [Obj_Classs],
        [_Year_Month],
        [_Count]
    ),
    [_Count] > 1
)

The result is as follow:

vzhengdxumsft_1-1715839740121.png

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Dyke211 

 

Thanks for the reply from @Jihwan_Kim , please allow me to provide another insight:

Create a measure:

MEASURE =
VAR _Event_Count =
    SUMMARIZE (
        ADDCOLUMNS (
            'Data',
            "_Year_Month", FORMAT ( 'Data'[Obj_Reported], "YYYY-MM" ),
            "_Count",
                CALCULATE (
                    COUNTROWS ( 'Data' ),
                    FILTER (
                        ALL ( Data ),
                        'Data'[Obj_Classs] = EARLIER ( Data[Obj_Classs] )
                            && YEAR ( 'Data'[Obj_Reported] ) = YEAR ( EARLIER ( 'Data'[Obj_Reported] ) )
                            && MONTH ( 'Data'[Obj_Reported] ) = MONTH ( EARLIER ( Data[Obj_Reported] ) )
                    )
                )
        ),
        [Obj_Classs],
        [_Year_Month],
        [_Count]
    )
RETURN
    COUNTROWS ( FILTER ( _Event_Count, [_Count] > 1 ) )

 The result:

vzhengdxumsft_0-1715839683511.png

Or you can create a table:

Table =
FILTER (
    SUMMARIZE (
        ADDCOLUMNS (
            'Data',
            "_Year_Month", FORMAT ( 'Data'[Obj_Reported], "YYYY-MM" ),
            "_Count",
                CALCULATE (
                    COUNTROWS ( 'Data' ),
                    FILTER (
                        ALL ( Data ),
                        'Data'[Obj_Classs] = EARLIER ( Data[Obj_Classs] )
                            && YEAR ( 'Data'[Obj_Reported] ) = YEAR ( EARLIER ( 'Data'[Obj_Reported] ) )
                            && MONTH ( 'Data'[Obj_Reported] ) = MONTH ( EARLIER ( Data[Obj_Reported] ) )
                    )
                )
        ),
        [Obj_Classs],
        [_Year_Month],
        [_Count]
    ),
    [_Count] > 1
)

The result is as follow:

vzhengdxumsft_1-1715839740121.png

 

Best Regards

Zhengdong Xu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1715794100387.png

 

 

Jihwan_Kim_0-1715794079240.png

 

 

More than once within the same month: =
VAR _t =
    SUMMARIZE (
        Data,
        Obj_Classs[Obj_Classs],
        'Calendar'[Year-Month sort],
        'Calendar'[Date]
    )
VAR _conditiontable =
    FILTER (
        ADDCOLUMNS (
            _t,
            "@appearancecount",
                COUNTROWS (
                    FILTER (
                        _t,
                        Obj_Classs[Obj_Classs] = EARLIER ( Obj_Classs[Obj_Classs] )
                            && 'Calendar'[Year-Month sort] = EARLIER ( 'Calendar'[Year-Month sort] )
                    )
                )
        ),
        [@appearancecount] > 1
    )
RETURN
    COUNTROWS ( SUMMARIZE ( _conditiontable, Obj_Classs[Obj_Classs] ) )

 



Microsoft MVP



If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.




LinkedInVisit my LinkedIn page




Outlook BookingSchedule a short Teams meeting to discuss your question



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.