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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
nhale777
New Member

Dynamic data in a calculated column based on row count.

I have a calculated column in one one of my tables that looks at an individuals age and then assigns them into a specific age grouping.  Very simple but I need to know based on the current company and date range selected on my report if any of the age groups will have less than a certain number of individuals,  if they do then I need to broaden the age grouping.  Not sure how to accomplish this in DAX.   Here is the current code,  any help is much appreciated.  Thanks.

 

IF (
Value([Age]) >= 60,
"60 & up",
IF (
Value([Age]) >= 55,
"55-59",
IF (
Value([Age]) >= 50,
"50-54",
IF (
Value([Age]) >= 45,
"45-49",
IF (
Value([Age]) >= 40,
"40-44",
IF (
Value([Age]) >= 35,
"35-39",
IF (
Value([AGE]) >= 30,
"30-34", "< 30" )
)
)
)
)
)
)
1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @nhale777 ,

According to your description, I create a sample table:

vyanjiangmsft_0-1685088543243.png

You want to know if any of the age groups will have less than a certain number of individuals, here's my solution:

Create a group table containing all the groups.

vyanjiangmsft_1-1685088653233.png

Then create a column to calculate the number of individuals belonging to each group:

Column =
COUNTROWS (
    FILTER (
        'Table',
        'Table'[Age]
            >= LEFT (
                [Group],
                SEARCH ( "&", [Group],, SEARCH ( "-", [Group],, SEARCH ( "<", [Group],, 0 ) ) ) - 1
            )
            && 'Table'[Age]
                < RIGHT (
                    [Group],
                    LEN ( [Group] )
                        - SEARCH ( "&", [Group],, SEARCH ( "-", [Group],, SEARCH ( "<", [Group],, 0 ) ) )
                )
    )
)

Get the correct result:

vyanjiangmsft_2-1685088746199.png

I attach my sample below for your reference.

 

Best regards,

Community Support Team_yanjiang

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

1 REPLY 1
v-yanjiang-msft
Community Support
Community Support

Hi @nhale777 ,

According to your description, I create a sample table:

vyanjiangmsft_0-1685088543243.png

You want to know if any of the age groups will have less than a certain number of individuals, here's my solution:

Create a group table containing all the groups.

vyanjiangmsft_1-1685088653233.png

Then create a column to calculate the number of individuals belonging to each group:

Column =
COUNTROWS (
    FILTER (
        'Table',
        'Table'[Age]
            >= LEFT (
                [Group],
                SEARCH ( "&", [Group],, SEARCH ( "-", [Group],, SEARCH ( "<", [Group],, 0 ) ) ) - 1
            )
            && 'Table'[Age]
                < RIGHT (
                    [Group],
                    LEN ( [Group] )
                        - SEARCH ( "&", [Group],, SEARCH ( "-", [Group],, SEARCH ( "<", [Group],, 0 ) ) )
                )
    )
)

Get the correct result:

vyanjiangmsft_2-1685088746199.png

I attach my sample below for your reference.

 

Best regards,

Community Support Team_yanjiang

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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