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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
tyxanu
Helper I
Helper I

Count of mixed values(text-integer)

Hi,

 

Can anyone help me achieve the below? 

 

I have these values in my PBi columns with my logic applied: for case type A I am counting hours passed till now, for case type B/C I am counting days passed till now.

 

Case | Latest comment date | Case type | Time passed till now

1 | 03-18-2022 09:56:36 AM | A | 97 hours

2 | 03-19-2022 15:35:23 PM | B | 3 days

3 | 03-21-2022 20:31:05 PM | C | 1 days

 

My desired output would be to count for all of these cases - how many are older than 1 week?

 

My DAX below returns incorrect results like: "303 hours < 168 hours: Yes", "5 days < 7 days: No"

 

IF('Source'[Case type]="A" && 'Source'[Time passed till now]>168 & " hours", "Yes","No")
IF('Source'[Case type]="B" && 'Source'[Time passed till now]>7 & " days", "Yes","No") 
IF('Source'[Case type]="C" && 'Source'[Time passed till now]>7 & " days", "Yes","No") 
 
Thank you!

 

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

Hi, @tyxanu ;

My DAX below returns incorrect results like: "303 hours < 168 hours: Yes", "5 days < 7 days: No"

IF('Source'[Case type]="A" && 'Source'[Time passed till now]>168 & " hours", "Yes","No")
IF('Source'[Case type]="B" && 'Source'[Time passed till now]>7 & " days", "Yes","No") 
IF('Source'[Case type]="C" && 'Source'[Time passed till now]>7 & " days", "Yes","No") 

You could create a column :

column = 
var _num=CONVERT( LEFT([Time passed till now], SEARCH(" ",[Time passed till now])),INTEGER)
return IF(('Source'[Case type]="A"&&_num>168)||
         (('Source'[Case type]="B"||'Source'[Case type]="C") &&_num>7),
         "Yes","No")

The final output is shown below:

vyalanwumsft_0-1648176689477.png


My desired output would be to count for all of these cases - how many are older than 1 week?


You could create a measure.

count = 
CALCULATE(COUNT([Case type]),FILTER(ALLSELECTED(Source),DATEDIFF([Latest comment date],NOW(),HOUR)>7*24))

The final output is shown below:

vyalanwumsft_1-1648177042523.png


Best Regards,
Community Support Team _ Yalan Wu
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

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi, @tyxanu ;

My DAX below returns incorrect results like: "303 hours < 168 hours: Yes", "5 days < 7 days: No"

IF('Source'[Case type]="A" && 'Source'[Time passed till now]>168 & " hours", "Yes","No")
IF('Source'[Case type]="B" && 'Source'[Time passed till now]>7 & " days", "Yes","No") 
IF('Source'[Case type]="C" && 'Source'[Time passed till now]>7 & " days", "Yes","No") 

You could create a column :

column = 
var _num=CONVERT( LEFT([Time passed till now], SEARCH(" ",[Time passed till now])),INTEGER)
return IF(('Source'[Case type]="A"&&_num>168)||
         (('Source'[Case type]="B"||'Source'[Case type]="C") &&_num>7),
         "Yes","No")

The final output is shown below:

vyalanwumsft_0-1648176689477.png


My desired output would be to count for all of these cases - how many are older than 1 week?


You could create a measure.

count = 
CALCULATE(COUNT([Case type]),FILTER(ALLSELECTED(Source),DATEDIFF([Latest comment date],NOW(),HOUR)>7*24))

The final output is shown below:

vyalanwumsft_1-1648177042523.png


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@tyxanu , My advice would be duplicate and split this column in power query. You will get a nueric column with hour. Then you can easily apply this logic

Split Column Power Query: https://youtu.be/FyO9Vmhcfag

This would be a way, but I don't want to overload the report. I am pretty sure a proper DAX similar to mine can be written.

 

Anyone? 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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