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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
HopkiJ
Frequent Visitor

Grouping data from calculated columns

Hi Everyone, I have been really struggling with a query on my data (very small sample below). 

I have presence data for when someone is in the office. I want to work out how many people are regular visitors and how many are infrequent attendees. This needs to be in buckets of 1-5 days per month, 6-10 days per month, etc. 

 

I have so far tried:

 

TotalVisits = 
CALCULATE(
    SUM('Table'[Present]),
    DATESBETWEEN('Date Table'[Dates], MIN('Date Table'[Dates]), MAX('Date Table'[Dates]))<p>Then:</p><p> <li-code lang="markup">Groups = switch(True(), 
[TotalVisits] <= 5, "1-5",
    IF(
        [TotalVisits] <= 10, "6-10",
        IF(
        [TotalVisits] <= 15, "11-15",
        "15+"
    )
))

 

 

 

However, the "Groups" will not show up on any visuals axis and only works in tables as an additional column. I really need to slice this data via the buckets above, any help would be greatly appreciated!

 

DateOffice IdentifierPerson IdentifierPresent
08.08.2024LDN1ABC1
08.08.2024GLA2XYZ1
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @HopkiJ ,

 

I modified the data and calculated columns.

vkaiyuemsft_0-1723796427392.png

Column = 
CALCULATE (
    COUNT ( 'Table'[Person Identifier] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Person Identifier] = EARLIER ( 'Table'[Person Identifier] )
            && 'Table'[Office Identifier] = EARLIER ( 'Table'[Office Identifier] )
            && YEAR ( 'Table'[Date] ) = YEAR ( EARLIER ( 'Table'[Date] ) )
            && MONTH ( 'Table'[Date] ) = MONTH ( EARLIER ( 'Table'[Date] ) )
    )
)

vkaiyuemsft_1-1723796460652.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @HopkiJ ,

 

Based on your description, I created this data.

vkaiyuemsft_0-1723531087093.png

 

Create a calculated column that counts the number of occurrences per person per month.

Column = 
CALCULATE (
    COUNT ( 'Table'[Person Identifier] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Person Identifier] = EARLIER ( 'Table'[Person Identifier] )
            && YEAR ( 'Table'[Date] ) = YEAR ( EARLIER ( 'Table'[Date] ) )
            && MONTH ( 'Table'[Date] ) = MONTH ( EARLIER ( 'Table'[Date] ) )
    )
)

 

Create calculated columns and group them.

Column2 = 
SWITCH (
    TRUE (),
    'Table'[Column] <= 5, "1-5",
    'Table'[Column] <= 10, "6-10",
    'Table'[Column] <= 15, "11-15",
    "15+"
)

 

vkaiyuemsft_1-1723531133905.png

 

vkaiyuemsft_2-1723531140786.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

Hi Clara

 

That appears to work for the most part, thank you! Do you know how I would get the office identifier to work with the filter as well? 

 

Many thanks

 

Jeni 

Anonymous
Not applicable

Hi @HopkiJ ,

 

I modified the data and calculated columns.

vkaiyuemsft_0-1723796427392.png

Column = 
CALCULATE (
    COUNT ( 'Table'[Person Identifier] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[Person Identifier] = EARLIER ( 'Table'[Person Identifier] )
            && 'Table'[Office Identifier] = EARLIER ( 'Table'[Office Identifier] )
            && YEAR ( 'Table'[Date] ) = YEAR ( EARLIER ( 'Table'[Date] ) )
            && MONTH ( 'Table'[Date] ) = MONTH ( EARLIER ( 'Table'[Date] ) )
    )
)

vkaiyuemsft_1-1723796460652.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

 

Thanks Clara, that worked a dream!

rajendraongole1
Super User
Super User

Hi @HopkiJ - Calculate the total number of visits per person for each month.

TotalVisitsPerMonth =
CALCULATE(
COUNTROWS('Table'),
ALLEXCEPT('Table', 'Table'[Person Identifier], 'Date Table'[Year-Month])
)

 

hope you already have a date table as mentioned formaule above, if not please create and add below new column

Year-Month = FORMAT([Dates], "YYYY-MM")

 

Next create another calculated column or measure to categorize these visits into your defined buckets like example

VisitGroup =
SWITCH(
TRUE(),
[TotalVisitsPerMonth] <= 5, "1-5",
[TotalVisitsPerMonth] <= 10, "6-10",
[TotalVisitsPerMonth] <= 15, "11-15",
"15+"
)

Now drag the visitgroup column in slicer and your visual (chart). 

 

it works

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Hi Rajendraongole1, 

Thank you fo ryour suggestion, this is imilar to others I have been attempting. However, this formula returns the bucket 1-5 for all lines which definitely isn't correct. 

HopkiJ_0-1723132505160.png

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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