cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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
Solution Sage
Solution Sage

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.

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors