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
devinep5
Frequent Visitor

Count values in column greater than or equal to different values

Hi,

I've been using the code below to separate values in a column into the ranges below.

However, my graph is showing only the first true value, "1 & Above" and ignoring the rest of the data ranges.
 
How would I get a count for the numbers that fall into ea

OverallStanineRangeAbove =
SWITCH (
TRUE(),
PT_1819[Overall Stanine] >= 1, "1 & Above",
PT_1819[Overall Stanine] >= 2, "2 & Above",
PT_1819[Overall Stanine] >= 3, "3 & Above",
PT_1819[Overall Stanine] >= 4, "4 & Above",
PT_1819[Overall Stanine] >= 5 , "5 & Above",
PT_1819[Overall Stanine] >= 6 , "6 & Above",
PT_1819[Overall Stanine] >= 7, "7 & Above",
PT_1819[Overall Stanine] >= 8, "8 & Above",
PT_1819[Overall Stanine] >= 9, "9 & Above",
Blank())
1 ACCEPTED SOLUTION

Hi @devinep5 ,

I have created this simple table initially:

overall.png

Is this your expected result?

result.png

If so, create a [OverallStanineRangeAbove] calculated column as x-axis using the previous formula:

 

OverallStanineRangeAbove = 
SWITCH (
TRUE(),
PT_1819[Overall Stanine] >= 9, "9 & Above",
PT_1819[Overall Stanine] >= 8, "8 & Above",
PT_1819[Overall Stanine] >= 7, "7 & Above",
PT_1819[Overall Stanine] >= 6, "6 & Above",
PT_1819[Overall Stanine] >= 5, "5 & Above",
PT_1819[Overall Stanine] >= 4, "4 & Above",
PT_1819[Overall Stanine] >= 3, "3 & Above",
PT_1819[Overall Stanine] >= 2, "2 & Above",
PT_1819[Overall Stanine] >= 1, "1 & Above",
Blank()
)

 

Then create a [Percentage] calculated column as y-axis using this formula:

 

Column = 
VAR _count =
    COUNT ( PT_1819[Overall Stanine] )
VAR _C1 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 1 ),
        [Overall Stanine]
    )
VAR _C2 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 2 ),
        [Overall Stanine]
    )
VAR _C3 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 3 ),
        [Overall Stanine]
    )
VAR _C4 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 4 ),
        [Overall Stanine]
    )
VAR _C5 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 5 ),
        [Overall Stanine]
    )
VAR _C6 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 6 ),
        [Overall Stanine]
    )
VAR _C7 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 7 ),
        [Overall Stanine]
    )
VAR _C8 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 8 ),
        [Overall Stanine]
    )
VAR _C9 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 9 ),
        [Overall Stanine]
    )
RETURN
    SWITCH (
        TRUE (),
        'PT_1819'[Overall Stanine] >= 9, _C9 / _count,
        'PT_1819'[Overall Stanine] >= 8, _C8 / _count,
        'PT_1819'[Overall Stanine] >= 7, _C7 / _count,
        'PT_1819'[Overall Stanine] >= 6, _C6 / _count,
        'PT_1819'[Overall Stanine] >= 5, _C5 / _count,
        'PT_1819'[Overall Stanine] >= 4, _C4 / _count,
        'PT_1819'[Overall Stanine] >= 3, _C3 / _count,
        'PT_1819'[Overall Stanine] >= 2, _C2 / _count,
        'PT_1819'[Overall Stanine] >= 1, _C1 / _count,
        BLANK ()
    )

 

It will get the above result in the column chart.

Attached my sample file that hopes to help you: Count values in column greater than or equal to different values.pbix

 

Best Regards,
Yingjie Li

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

4 REPLIES 4
amitchandak
Super User
Super User

@devinep5 , Change the order

OverallStanineRangeAbove =
SWITCH (
TRUE(),
PT_1819[Overall Stanine] >= 9, "9 & Above",
PT_1819[Overall Stanine] >= 8, "8 & Above",
PT_1819[Overall Stanine] >= 7, "7 & Above",
PT_1819[Overall Stanine] >= 6 , "6 & Above",
PT_1819[Overall Stanine] >= 5 , "5 & Above",
PT_1819[Overall Stanine] >= 4, "4 & Above",
PT_1819[Overall Stanine] >= 3, "3 & Above",
PT_1819[Overall Stanine] >= 2, "2 & Above",
PT_1819[Overall Stanine] >= 1, "1 & Above",
Blank())

 

Apologies, I hadn't unfiltered the data before replying to you.
The bottom graph is what it looks like now. As you can see, "1 & above" should be 100% (because everyone has achieved at elast a 1 mark), biut the percentage as you can see in the screenshot below is showing only 1%.

devinep5_0-1594665075302.png

 

Hi @devinep5 ,

I have created this simple table initially:

overall.png

Is this your expected result?

result.png

If so, create a [OverallStanineRangeAbove] calculated column as x-axis using the previous formula:

 

OverallStanineRangeAbove = 
SWITCH (
TRUE(),
PT_1819[Overall Stanine] >= 9, "9 & Above",
PT_1819[Overall Stanine] >= 8, "8 & Above",
PT_1819[Overall Stanine] >= 7, "7 & Above",
PT_1819[Overall Stanine] >= 6, "6 & Above",
PT_1819[Overall Stanine] >= 5, "5 & Above",
PT_1819[Overall Stanine] >= 4, "4 & Above",
PT_1819[Overall Stanine] >= 3, "3 & Above",
PT_1819[Overall Stanine] >= 2, "2 & Above",
PT_1819[Overall Stanine] >= 1, "1 & Above",
Blank()
)

 

Then create a [Percentage] calculated column as y-axis using this formula:

 

Column = 
VAR _count =
    COUNT ( PT_1819[Overall Stanine] )
VAR _C1 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 1 ),
        [Overall Stanine]
    )
VAR _C2 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 2 ),
        [Overall Stanine]
    )
VAR _C3 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 3 ),
        [Overall Stanine]
    )
VAR _C4 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 4 ),
        [Overall Stanine]
    )
VAR _C5 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 5 ),
        [Overall Stanine]
    )
VAR _C6 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 6 ),
        [Overall Stanine]
    )
VAR _C7 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 7 ),
        [Overall Stanine]
    )
VAR _C8 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 8 ),
        [Overall Stanine]
    )
VAR _C9 =
    COUNTX (
        FILTER ( 'PT_1819', 'PT_1819'[Overall Stanine] >= 9 ),
        [Overall Stanine]
    )
RETURN
    SWITCH (
        TRUE (),
        'PT_1819'[Overall Stanine] >= 9, _C9 / _count,
        'PT_1819'[Overall Stanine] >= 8, _C8 / _count,
        'PT_1819'[Overall Stanine] >= 7, _C7 / _count,
        'PT_1819'[Overall Stanine] >= 6, _C6 / _count,
        'PT_1819'[Overall Stanine] >= 5, _C5 / _count,
        'PT_1819'[Overall Stanine] >= 4, _C4 / _count,
        'PT_1819'[Overall Stanine] >= 3, _C3 / _count,
        'PT_1819'[Overall Stanine] >= 2, _C2 / _count,
        'PT_1819'[Overall Stanine] >= 1, _C1 / _count,
        BLANK ()
    )

 

It will get the above result in the column chart.

Attached my sample file that hopes to help you: Count values in column greater than or equal to different values.pbix

 

Best Regards,
Yingjie Li

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

Thanks for the reply, however, it's still showing only one data range, "1 & above".

Essentially what I'm trying to do is have on the X-axis, total achieving "1 & above", "2 & above", etc.

 

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.