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
Jason6
Helper I
Helper I

How to calculate >30 days and report for existing month

I have a dataset where i need to track repeat event logged for 0-3, 4-10, 10-30 and >30 for a unique events occuring in a month.

So the columns are as per below , i add a calculated column to capture first report date for each line item and calculate the "Gap"

 

Jason6_1-1663612369326.png

Then i create a measure to check records >30 days and <30 days . Problem is in below screenshot the >30 appears for Aug'22 for Tel # 123 but it is actually >30 days from the event from July'22

Jason6_2-1663612398072.png

What measure should i use to calculate >30 so that it gets reported in July'22 itself as per screenshot below

 

Jason6_3-1663612710743.png

 

 

1 ACCEPTED SOLUTION
alena2k
Resolver IV
Resolver IV

hi @Jason6 

here is my suggestion for each of measures:

> 30 = 
var tmp = CALCULATE(DISTINCTCOUNT('Table'[Tel #]),
                     ALL('Table'), 
                    'Table'[Tel #] = SELECTEDVALUE('Table'[Tel #]), 
                    'Table'[DateReported] > SELECTEDVALUE('Table'[DateReported]),
                    'Table'[Gap] - SELECTEDVALUE('Table'[Gap]) > 30)
RETURN IF(ISBLANK(tmp), 0, tmp)
< 15 = 
var tmp = CALCULATE(DISTINCTCOUNT('Table'[Tel #]),
                     ALL('Table'), 
                    'Table'[Tel #] = SELECTEDVALUE('Table'[Tel #]), 
                    'Table'[DateReported] > SELECTEDVALUE('Table'[DateReported]),
                     AND('Table'[Gap] - SELECTEDVALUE('Table'[Gap]) < 15, 'Table'[Gap] - SELECTEDVALUE('Table'[Gap]) > 3))
RETURN IF(ISBLANK(tmp), 0, tmp)
< 3 = 
var tmp = CALCULATE(DISTINCTCOUNT('Table'[Tel #]),
                     ALL('Table'), 
                    'Table'[Tel #] = SELECTEDVALUE('Table'[Tel #]), 
                    'Table'[DateReported] > SELECTEDVALUE('Table'[DateReported]),
                     AND('Table'[Gap] - SELECTEDVALUE('Table'[Gap]) > 0, 'Table'[Gap] - SELECTEDVALUE('Table'[Gap]) < 3))
RETURN IF(ISBLANK(tmp), 0, tmp)

The idea is to check if there are any records in future including next months. 

ALL('Table') allows to step out of current context by Tel# and Month. I would use the same approach for all measures in case if you have reports at the end of the month followed by beginning of the next (e.g. 7/31, 8/1)

View solution in original post

2 REPLIES 2
alena2k
Resolver IV
Resolver IV

hi @Jason6 

here is my suggestion for each of measures:

> 30 = 
var tmp = CALCULATE(DISTINCTCOUNT('Table'[Tel #]),
                     ALL('Table'), 
                    'Table'[Tel #] = SELECTEDVALUE('Table'[Tel #]), 
                    'Table'[DateReported] > SELECTEDVALUE('Table'[DateReported]),
                    'Table'[Gap] - SELECTEDVALUE('Table'[Gap]) > 30)
RETURN IF(ISBLANK(tmp), 0, tmp)
< 15 = 
var tmp = CALCULATE(DISTINCTCOUNT('Table'[Tel #]),
                     ALL('Table'), 
                    'Table'[Tel #] = SELECTEDVALUE('Table'[Tel #]), 
                    'Table'[DateReported] > SELECTEDVALUE('Table'[DateReported]),
                     AND('Table'[Gap] - SELECTEDVALUE('Table'[Gap]) < 15, 'Table'[Gap] - SELECTEDVALUE('Table'[Gap]) > 3))
RETURN IF(ISBLANK(tmp), 0, tmp)
< 3 = 
var tmp = CALCULATE(DISTINCTCOUNT('Table'[Tel #]),
                     ALL('Table'), 
                    'Table'[Tel #] = SELECTEDVALUE('Table'[Tel #]), 
                    'Table'[DateReported] > SELECTEDVALUE('Table'[DateReported]),
                     AND('Table'[Gap] - SELECTEDVALUE('Table'[Gap]) > 0, 'Table'[Gap] - SELECTEDVALUE('Table'[Gap]) < 3))
RETURN IF(ISBLANK(tmp), 0, tmp)

The idea is to check if there are any records in future including next months. 

ALL('Table') allows to step out of current context by Tel# and Month. I would use the same approach for all measures in case if you have reports at the end of the month followed by beginning of the next (e.g. 7/31, 8/1)
jgeddes
Super User
Super User

You will need a column that defines the month/year for the first reported event. The month column you are currently using appears to be based on the date reported. 

Create the new month column and use that in your visual and you should end up with the desired result.




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

Proud to be a Super User!





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.