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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
RajivRavichand
Frequent Visitor

Need to write in Switch statement with between condition or is there any buitin function

Hi All,
 
I need to write the below expression in switch or is there any buit in function generate the series of between numbers.
 
Thanks
Rajiv
 
 
 
SysTimeRange1 =

if (Consolidated_Data[System Time Min] > 0 && Consolidated_Data[System Time Min] < 1, "0-1",
if (Consolidated_Data[System Time Min] > 1 && Consolidated_Data[System Time Min]  < 2, "1-2",
if (Consolidated_Data[System Time Min] > 2 && Consolidated_Data[System Time Min]  < 3, "2-3",
if (Consolidated_Data[System Time Min] > 3 && Consolidated_Data[System Time Min]  < 4, "3-4",
if (Consolidated_Data[System Time Min] > 4 && Consolidated_Data[System Time Min]  < 5, "4-5",
if (Consolidated_Data[System Time Min] > 5 && Consolidated_Data[System Time Min]  < 6, "5-6",
if (Consolidated_Data[System Time Min] > 6 && Consolidated_Data[System Time Min]  < 7, "6-7",
if (Consolidated_Data[System Time Min] > 7 && Consolidated_Data[System Time Min]  < 8, "7-8",
if (Consolidated_Data[System Time Min] > 8 && Consolidated_Data[System Time Min]  < 9, "8-9",
if (Consolidated_Data[System Time Min] > 9 && Consolidated_Data[System Time Min]  < 10, "9-10"))))))))))
1 ACCEPTED SOLUTION

Hi @RajivRavichand ,

I reproduced your problem with the formula you provided.

vkalyjmsft_0-1666254393259.png

If you only return the selectedvalue, you'll find it's blank, SELECTEDVALUE isn't suitable here.

vkalyjmsft_1-1666254527456.png

Just modify the formula to:

Column = 
VAR Val = Consolidated_Data[System Time Min]
RETURN
    SWITCH (
        TRUE (),
         Val >= 0 && Val < 1 , "0-1",
         Val >= 1 && Val < 2 , "1-2",
         Val >= 2 && Val < 3 , "2-3",
         Val >= 3 && Val < 4 , "3-4",
         Val >= 4 && Val < 5 , "4-5",
         Val >= 5 && Val < 6 , "5-6",
         Val >= 6 && Val < 7 , "6-7",
         Val >= 7 && Val < 8 , "7-8",
         Val >= 8 && Val < 9 , "8-9",
         Val >= 9 && Val < 10 , "9-10")

Get the correct result.

vkalyjmsft_2-1666254679733.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

6 REPLIES 6
rsbin
Super User
Super User

@RajivRavichand ,

The structure of the SWITCH statement is this:

SysTimeRange1 = SWITCH(
                    TRUE(),
             Consolidated_Data[System Time Min] > 0 && 
              Consolidated_Data[System Time Min] < 1, "0-1",
             Consolidated_Data[System Time Min] > 1 
             && Consolidated_Data[System Time Min] < 2, "1-2",
             etc....

I notice you do not have any equal signs in your example.  If you have instances where [System Time Min] will equal a whole number, you will need to account for these in your Conditions.

Trust this helps.

Regards,

Thanks for your reply. Initially I tried with below switch but alwys returns "0-1" for all rows. That's why moved to nested if. In nested if it is working fine. but i have write up to 60 mins. Is there any builtin function? or any solution?

 

DAX:

SysTimeRange =
VAR Val = SELECTEDVALUE ( Consolidated_Data[System Time Min] )
RETURN
    SWITCH (
        TRUE (),
         Val >= 0 && Val < 1 , "0-1",
         Val >= 1 && Val < 2 , "1-2",
         Val >= 3 && Val < 4 , "3-4",
         Val >= 5 && Val < 6 , "5-6",
         Val >= 7 && Val < 8 , "7-8",
         Val >= 9 && Val < 10 , "9-10")

Selected Value returns single value.. Switch is working fine. Please let me know is there any built in function for this.

Hi @RajivRavichand ,

I reproduced your problem with the formula you provided.

vkalyjmsft_0-1666254393259.png

If you only return the selectedvalue, you'll find it's blank, SELECTEDVALUE isn't suitable here.

vkalyjmsft_1-1666254527456.png

Just modify the formula to:

Column = 
VAR Val = Consolidated_Data[System Time Min]
RETURN
    SWITCH (
        TRUE (),
         Val >= 0 && Val < 1 , "0-1",
         Val >= 1 && Val < 2 , "1-2",
         Val >= 2 && Val < 3 , "2-3",
         Val >= 3 && Val < 4 , "3-4",
         Val >= 4 && Val < 5 , "4-5",
         Val >= 5 && Val < 6 , "5-6",
         Val >= 6 && Val < 7 , "6-7",
         Val >= 7 && Val < 8 , "7-8",
         Val >= 8 && Val < 9 , "8-9",
         Val >= 9 && Val < 10 , "9-10")

Get the correct result.

vkalyjmsft_2-1666254679733.png

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

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

Yes, It works fine. Thanks. Is ther any built in function to get the automatted values.

Hi @RajivRavichand ,

My pleasure!

As far as I know, SWITCH and IF are the general function in this type of problems.

Best Regards,
Community Support Team _ kalyj

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.

Top Solution Authors