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
EWBWEBB
Helper III
Helper III

Counting instances

Hi there

 

I am trying to count the instances of Covid over a period of time.

 

There are two piece to this.

1.) how do I count the instances where the first instance would be labelled 1 and the second as 2, third as 3 and so on. Using earlier seems to mark them all as the highest count. so the first second and third would all show a count of 3.

 

2.) I'd like to do this to see if the number of multiple instances has changed year on year. So count the first one in the year as 1, second as 2 then the next year restart the count at 1, and so on.

 

My data is laid out as follows 

From DateUNID
19/03/2020F005F
15/11/2020F0040
20/01/2021Y8F44
01/03/2021F00FF
04/03/2021F0078
09/06/2021Y8F08
30/06/2021F005F
20/07/2021a0588
30/07/2021F00FF
14/09/2021F00FF
25/09/2021F00FF
19/11/2021F0090
12/12/2021Y8F44
03/01/2022a058F
23/05/2022a0584
01/06/2022a0588
05/07/2022F00FF
11/07/2022F0078

 

I have a caelndar (simple just every day of the year) joined on from date 1-Many.

 

This would be my expected result.

 

  expected result 
  Total CountIn Year Count
From DateUNID  
19/03/2020F005F11
15/11/2020F004011
20/01/2021Y8F4411
01/03/2021F00FF11
04/03/2021F007811
09/06/2021Y8F0811
30/06/2021F005F21
20/07/2021a058811
30/07/2021F00FF22
14/09/2021F00FF33
25/09/2021F00FF44
19/11/2021F009011
12/12/2021Y8F4422
03/01/2022a058F11
23/05/2022a058411
01/06/2022a058821
05/07/2022F00FF51
11/07/2022F007821

 

From this I would then like to be able to count the number of people with multiple instances in each year and the average number of instances - which should be pretty straight forward if this is a calculated column. 

 

2 ACCEPTED SOLUTIONS
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1667393793721.png

 

Total count CC = 
COUNTROWS (
    FILTER (
        Data,
        Data[UNID] = EARLIER ( Data[UNID] )
            && Data[From Date] <= EARLIER ( Data[From Date] )
    )
)

 

In year count CC = 
COUNTROWS (
    FILTER (
        Data,
        Data[UNID] = EARLIER ( Data[UNID] )
            && YEAR ( Data[From Date] ) = YEAR ( EARLIER ( Data[From Date] ) )
            && Data[From Date] <= EARLIER ( Data[From Date] )
    )
)

 

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

Hi,

Thank you for your reply.

I am not sure if I correctly understood your second questions, but please check the below picture and the attached pbix file whether it suits your requirement.

 

Jihwan_Kim_0-1667401221163.png

 

 

Expected CC =
VAR _toponebyyeartable =
    TOPN (
        1,
        FILTER (
            Data,
            Data[UNID] = EARLIER ( Data[UNID] )
                && YEAR ( Data[From Date] ) = YEAR ( EARLIER ( Data[From Date] ) )
        ),
        Data[In year count CC], DESC
    )
RETURN
    IF (
        MAXX ( _toponebyyeartable, Data[In year count CC] ) = Data[In year count CC],
        Data[In year count CC]
    )

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

4 REPLIES 4
EWBWEBB
Helper III
Helper III

@Jihwan_Kim This is perfect thank you.

So the next step - Is there a way that just the most recent instance in each year is marked?

I.e for those that have just 1 instance in a year we get a 1, for those that have had 2 instances in a year the first instance in blank and the second is mark as 2 and so on?

When I count this the 1 is throwing the figures off a little as someone with 2 or more instances is also appearing in the column counting their first and second instance as well.

Hi,

Thank you for your reply.

I am not sure if I correctly understood your second questions, but please check the below picture and the attached pbix file whether it suits your requirement.

 

Jihwan_Kim_0-1667401221163.png

 

 

Expected CC =
VAR _toponebyyeartable =
    TOPN (
        1,
        FILTER (
            Data,
            Data[UNID] = EARLIER ( Data[UNID] )
                && YEAR ( Data[From Date] ) = YEAR ( EARLIER ( Data[From Date] ) )
        ),
        Data[In year count CC], DESC
    )
RETURN
    IF (
        MAXX ( _toponebyyeartable, Data[In year count CC] ) = Data[In year count CC],
        Data[In year count CC]
    )

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.

Spoth on @Jihwan_Kim - thank you so much

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_0-1667393793721.png

 

Total count CC = 
COUNTROWS (
    FILTER (
        Data,
        Data[UNID] = EARLIER ( Data[UNID] )
            && Data[From Date] <= EARLIER ( Data[From Date] )
    )
)

 

In year count CC = 
COUNTROWS (
    FILTER (
        Data,
        Data[UNID] = EARLIER ( Data[UNID] )
            && YEAR ( Data[From Date] ) = YEAR ( EARLIER ( Data[From Date] ) )
            && Data[From Date] <= EARLIER ( Data[From Date] )
    )
)

 

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
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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