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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
JamesMF1982
Frequent Visitor

Categorise values in a measure not a column

Hi,

 

I want to be able to categorise dates into a number of categories and then put them into a pie chart, now I know the best way is to put them into a column, however I am pulling a dataset that isn't able to modified by myself and would be chargeable by our third party and so a measure would be free.

 

I worked what the column calculation would be:

 

EnquiryDaysToConvert = if(ENQUIRYDETAILS[EnquiryCurrentStageID] = 3,
if(DATEDIFF(ENQUIRYDETAILS[EnquiryBecameLeadDate],ENQUIRYDETAILS[EnquiryBecameClient],DAY)<=10,"0 - 10 days",
if(DATEDIFF(ENQUIRYDETAILS[EnquiryBecameLeadDate],ENQUIRYDETAILS[EnquiryBecameClient],DAY)<=15,"11 - 15 days",
if(DATEDIFF(ENQUIRYDETAILS[EnquiryBecameLeadDate],ENQUIRYDETAILS[EnquiryBecameClient],DAY)<=20,"0 - 20 days",
if(DATEDIFF(ENQUIRYDETAILS[EnquiryBecameLeadDate],ENQUIRYDETAILS[EnquiryBecameClient],DAY)<=25,"21 - 25 days",
if(DATEDIFF(ENQUIRYDETAILS[EnquiryBecameLeadDate],ENQUIRYDETAILS[EnquiryBecameClient],DAY)<=30,"26 - 30 days","Over 30 days"))))),"")

 

However, I am not sure if this can be transferred to a measure. Any help would be amazing thank you

 

James

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

Hi , @JamesMF1982 

According to your description, you want to convert the calculated column to the measure , you can try to use this dax:

EnquiryDaysToConvert = 
if(ENQUIRYDETAILS[EnquiryCurrentStageID] = 3,
SWITCH(
True(),
DATEDIFF(max(ENQUIRYDETAILS[EnquiryBecameLeadDate]),max(ENQUIRYDETAILS[EnquiryBecameClient]),DAY)<=10,"0 - 10 days",
DATEDIFF(max(ENQUIRYDETAILS[EnquiryBecameLeadDate]),max(ENQUIRYDETAILS[EnquiryBecameClient]),DAY)<=15,"11 - 15 days",
DATEDIFF(max(ENQUIRYDETAILS[EnquiryBecameLeadDate]),max(ENQUIRYDETAILS[EnquiryBecameClient]),DAY)<=20,"0 - 20 days",
DATEDIFF(max(ENQUIRYDETAILS[EnquiryBecameLeadDate]),max(ENQUIRYDETAILS[EnquiryBecameClient]),DAY)<=25,"21 - 25 days",
if(DATEDIFF(max(ENQUIRYDETAILS[EnquiryBecameLeadDate]),max(ENQUIRYDETAILS[EnquiryBecameClient]),DAY)<=30,"26 - 30 days",
"Over 30 days"),blank())

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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-yueyunzh-msft
Community Support
Community Support

Hi , @JamesMF1982 

According to your description, you want to convert the calculated column to the measure , you can try to use this dax:

EnquiryDaysToConvert = 
if(ENQUIRYDETAILS[EnquiryCurrentStageID] = 3,
SWITCH(
True(),
DATEDIFF(max(ENQUIRYDETAILS[EnquiryBecameLeadDate]),max(ENQUIRYDETAILS[EnquiryBecameClient]),DAY)<=10,"0 - 10 days",
DATEDIFF(max(ENQUIRYDETAILS[EnquiryBecameLeadDate]),max(ENQUIRYDETAILS[EnquiryBecameClient]),DAY)<=15,"11 - 15 days",
DATEDIFF(max(ENQUIRYDETAILS[EnquiryBecameLeadDate]),max(ENQUIRYDETAILS[EnquiryBecameClient]),DAY)<=20,"0 - 20 days",
DATEDIFF(max(ENQUIRYDETAILS[EnquiryBecameLeadDate]),max(ENQUIRYDETAILS[EnquiryBecameClient]),DAY)<=25,"21 - 25 days",
if(DATEDIFF(max(ENQUIRYDETAILS[EnquiryBecameLeadDate]),max(ENQUIRYDETAILS[EnquiryBecameClient]),DAY)<=30,"26 - 30 days",
"Over 30 days"),blank())

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

pi_eye
Resolver IV
Resolver IV

Hi @JamesMF1982 , 

 

There exists a "switch" statement in DAX - https://dax.guide/switch/.

For example this measure works for me:

Measure = IF(SELECTEDVALUE(Sheet1[yearmonth]) <= 202210,  
switch(TRUE,

AND (sum(Sheet1[cal1])>10, sum(Sheet1[cal1])<=20),">10 <=20",
sum(Sheet1[cal1])>40,">40",
sum(Sheet1[cal1])>30,">30")
)
For your requirement , this would look something like:
EnquiryDaysToConvert = if(ENQUIRYDETAILS[EnquiryCurrentStageID] = 3,
SWITCH(
DATEDIFF(ENQUIRYDETAILS[EnquiryBecameLeadDate],ENQUIRYDETAILS[EnquiryBecameClient],DAY)<=10,"0 - 10 days",
DATEDIFF(ENQUIRYDETAILS[EnquiryBecameLeadDate],ENQUIRYDETAILS[EnquiryBecameClient],DAY)<=15,"11 - 15 days",
DATEDIFF(ENQUIRYDETAILS[EnquiryBecameLeadDate],ENQUIRYDETAILS[EnquiryBecameClient],DAY)<=20,"0 - 20 days",.......))
 
HTH
 
Pi

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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