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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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.


Click here and Go to My LinkedIn Page


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.


Click here and Go to My LinkedIn Page


Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.