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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Switch condition issue in DAX

Hello All,

 

I have report where I am showing sales and for each date.

My data is like below

 

TrendType      Date                Sales

Daily12/8/2022    100
Daily12/9/2022     100
Daily12/10/2022     90
Daily12/11/2022    250
Daily12/12/2022     210
Daily12/13/2022    450
Daily12/14/2022     80
Daily12/15/2022    70
Daily12/16/2022    290
Daily12/17/2022    600
Daily12/18/2022   700
Daily12/19/2022    50
Monthly11/1/2022   450
Monthly10/1/2022   600
Monthly9/1/2022    700
Monthly8/1/2022300
Monthly7/1/2022100
Monthly6/1/2022180
Monthly5/1/2022650
Monthly4/1/2022800
Monthly3/1/2022260
Monthly2/1/2022170
Monthly1/1/2022760
Monthly12/1/2021150

 

I created a sles KPI which will show like below.

 

KPI_Sales = SWITCH(TRUE(),
sum(Sheet1[Sales]) <=1000, 5,
sum(Sheet1[Sales]) <=600, 4,
sum(Sheet1[Sales])  <=300, 3,
sum(Sheet1[Sales]) <=200, 2,
1)


//if sum of sales <= 200 then 2
//if sum of sales >200 and lessthan equal to 300 then 3
//if sum of sales >300 and lessthan equal to 600 then 4
//if sum of sales >600 and lessthan equal to 1000  then 5
 
 

But when I show the kpi for each date I am not getting accurate results.

For all sales the kpi is showing 5.

 

Am I doing anything wrong here.

Please suggest

 

 

Sathvik123_1-1671429582772.png

 

1 ACCEPTED SOLUTION
Mahesh0016
Super User
Super User

Mahesh0016_0-1671430937293.png

Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

View solution in original post

3 REPLIES 3
jhavdn
Regular Visitor

Hi, the wwitch statement checks every condition as put in so in your case the first one is checks if the outcome is below 1000 (thats true in every case).

try this:

KPI_Sales = SWITCH(TRUE(),
sum(Sheet1[Sales]) <=200, 2,
sum(Sheet1[Sales])  <=300, 3,
sum(Sheet1[Sales]) <=6004,
sum(Sheet1[Sales]) <=10005,
1)
 
if you check it this way you should get better results.
Mahesh0016
Super User
Super User

Mahesh0016_0-1671430937293.png

Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

amitchandak
Super User
Super User

@Anonymous , You need to create Dynamic Segmentation Bucketing Binning
https://community.powerbi.com/t5/Quick-Measures-Gallery/Dynamic-Segmentation-Bucketing-Binning/m-p/1387187#M626


Dynamic Segmentation, Bucketing or Binning: https://youtu.be/CuczXPj0N-k

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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