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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Laura0403
Frequent Visitor

Calculated Column with a result between two values -- if statement

Hello,

 

I am currenctly trying to write a calculated column to Filter Visuals.

I would like to use it to filter what weight range a shipment is in.

 

Now I have done this (sorry, it won't let me insert this as Code):

 
Filter_Gewichtstaffel =
IF (
    frkostsoll[gewicht] >= 0
        || frkostsoll[gewicht] <= 1.99,
    "0-1,99",
    IF (
        frkostsoll[gewicht] >= 2
            || frkostsoll[gewicht] <= 4.99,
        "2-4,99",
        IF (
            frkostsoll[gewicht] >= 5
                || frkostsoll[gewicht] <= 9.99,
            "5-9,99",
            IF (
                frkostsoll[gewicht] >= 10
                    || frkostsoll[gewicht] <= 14.99,
                "10-14,99",
                IF (
                    frkostsoll[gewicht] >= 15
                        || frkostsoll[gewicht] <= 24.99,
                    "15-24,99",
                    IF (
                        frkostsoll[gewicht] >= 25
                            || frkostsoll[gewicht] <= 29.99,
                        "25-29,99",
                        IF (
                            frkostsoll[gewicht] >= 30
                                || frkostsoll[gewicht] <= 39.99,
                            "30-39,99",
                            IF (
                                frkostsoll[gewicht] >= 40
                                    || frkostsoll[gewicht] <= 59.99,
                                "40-59,99",
                                IF (
                                    frkostsoll[gewicht] >= 60
                                        || frkostsoll[gewicht] <= 79.99,
                                    "60-79,99",
                                    IF ( frkostsoll[gewicht] >= 80, ">=80", "N.v." )
                                )
                            )
                        )
                    )
                )
            )
        )
    )
)

PS: the Column is formatted as number.

Can someone help me? Something is clearly wrong.

 

Thanks in advance

Laura

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @Laura0403 ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_1-1682043682770.png

Please try:

 

Filter_Gewichtstaffel =
SWITCH (
    TRUE (),
    frkostsoll[gewicht] >= 0
        && frkostsoll[gewicht] <= 1.99, "0-1,99",
    frkostsoll[gewicht] >= 2
        && frkostsoll[gewicht] <= 4.99, "2-4,99",
    frkostsoll[gewicht] >= 5
        && frkostsoll[gewicht] <= 9.99, "5-9,99",
    frkostsoll[gewicht] >= 10
        && frkostsoll[gewicht] <= 14.99, "10-14,99",
    frkostsoll[gewicht] >= 15
        && frkostsoll[gewicht] <= 24.99, "15-24,99",
    frkostsoll[gewicht] >= 25
        && frkostsoll[gewicht] <= 29.99, "25-29,99",
    frkostsoll[gewicht] >= 30
        && frkostsoll[gewicht] <= 39.99, "30-39,99",
    frkostsoll[gewicht] >= 40
        && frkostsoll[gewicht] <= 59.99, "40-59,99",
    frkostsoll[gewicht] >= 60
        && frkostsoll[gewicht] <= 79.99, "60-79,99",
    frkostsoll[gewicht] >= 80, ">=80",
    "N.v."
)

 

Final output:

vjianbolimsft_2-1682043702363.png

Best Regards,

Jianbo 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

2 REPLIES 2
v-jianboli-msft
Community Support
Community Support

Hi @Laura0403 ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_1-1682043682770.png

Please try:

 

Filter_Gewichtstaffel =
SWITCH (
    TRUE (),
    frkostsoll[gewicht] >= 0
        && frkostsoll[gewicht] <= 1.99, "0-1,99",
    frkostsoll[gewicht] >= 2
        && frkostsoll[gewicht] <= 4.99, "2-4,99",
    frkostsoll[gewicht] >= 5
        && frkostsoll[gewicht] <= 9.99, "5-9,99",
    frkostsoll[gewicht] >= 10
        && frkostsoll[gewicht] <= 14.99, "10-14,99",
    frkostsoll[gewicht] >= 15
        && frkostsoll[gewicht] <= 24.99, "15-24,99",
    frkostsoll[gewicht] >= 25
        && frkostsoll[gewicht] <= 29.99, "25-29,99",
    frkostsoll[gewicht] >= 30
        && frkostsoll[gewicht] <= 39.99, "30-39,99",
    frkostsoll[gewicht] >= 40
        && frkostsoll[gewicht] <= 59.99, "40-59,99",
    frkostsoll[gewicht] >= 60
        && frkostsoll[gewicht] <= 79.99, "60-79,99",
    frkostsoll[gewicht] >= 80, ">=80",
    "N.v."
)

 

Final output:

vjianbolimsft_2-1682043702363.png

Best Regards,

Jianbo Li

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

Hi Jianbo Li,
thanks a lot. I don't know why I haven't thought about the switch.
I guess my brain had some problems that day 😄 

 

Now it works, thanks a lot.

Laura 🙂 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.