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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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