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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. 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] ) )

 

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

View solution in original post

v-zhengdxu-msft
Community Support
Community Support

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
v-zhengdxu-msft
Community Support
Community Support

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] ) )

 

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.


Visit my LinkedIn page by clicking here.


Schedule a meeting with me to discuss further by clicking here.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.