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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

Pre & Post Analysis

Hello All,

I am trying to count the number of calls before and after a particular date: I have the following tables
All calls Table(It has dates(from 2018 to Date), Incident numbers,patient names,age etc)

Patient Table(It has patient names(ABOUT 61), Date of enrollment into a program(September 15, 2021, same for all 61 patients), and DOB)

I have linked the two tables together in the data model.

End Goal: I am trying to get a count of calls 6 months before and after the date of enrollment for the patients in the second table relative to the first table

Second Goal: Is to get a percentage count of the patient table to the general call volume in the Call Table.

 

Any Ideas are welcome. Thank You. Cannot share the main data due to the sensitive nature

 

2 ACCEPTED SOLUTIONS

Hi @Anonymous ,

 

6 months before and after date of enrollment.

You need a table contains a column which used to be the Axis like line chart you provided. I create a table like this:

vchenwuzmsft_0-1646808828545.png

Then create a measure via this code:

Measure =
VAR _d =
    CALCULATE (
        SELECTEDVALUE ( Patients[Date of Review] ),
        ALLNOBLANKROW ( Patients )
    )
VAR _diff =
    SELECTEDVALUE ( 'Axis'[value] )
VAR _datestart =
    DATE ( YEAR ( _d ), MONTH ( _d ) + _diff, 1 )
VAR _dateend =
    DATE ( YEAR ( _d ), MONTH ( _d ) + _diff + 1, 1 ) - 1
RETURN
    IF (
        SELECTEDVALUE ( Patients[Full Name] ) = BLANK (),
        COUNTROWS (
            FILTER (
                ALL ( 'Calls' ),
                [Incident Date Time] >= _datestart
                    && [Incident Date Time] <= _dateend
            )
        ),
        COUNTROWS (
            FILTER (
                'Calls',
                [Incident Date Time] >= _datestart
                    && [Incident Date Time] <= _dateend
            )
        )
    )

Before you use this measure correctly, a relationship between calls and patients on name need to be created.

vchenwuzmsft_2-1646809758090.png

 

And result:

vchenwuzmsft_3-1646809799525.png

 

 

 

Best Regards!

Community Support Team _ chenwu zhu

 

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

Hi @Anonymous ,

 

Response of your questions.

2. The Axis table ( dimmonth ) was created by enter data, so just remove -6 month and others you do not want, but keep the [value] is right due to the [value] is identified as parameter for the DAX formula.

 

1. Sort the column(dimmonth) by [value] column.

vchenwuzmsft_0-1646879856331.png

 

3 If there are different review date for each patient, please use this code:

 

Measure =
VAR _diff =
    SELECTEDVALUE ( 'Axis'[value] )
VAR _s =
    SUMMARIZE (
        'Patients',
        Patients[Full Name],
        Patients[Date of Review],
        "COUNT",
            COUNTROWS (
                FILTER (
                    'Calls',
                    [Incident Date Time]
                        >= DATE ( YEAR ( EARLIER ( Patients[Date of Review] ) ), MONTH ( EARLIER ( Patients[Date of Review] ) ) + _diff, 1 )
                        && [Incident Date Time]
                            <= (
                                DATE ( YEAR ( EARLIER ( Patients[Date of Review] ) ), MONTH ( EARLIER ( Patients[Date of Review] ) ) + _diff + 1, 1 ) - 1
                            )
                )
            )
    )
RETURN
    SUMX ( _s, [COUNT] )

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

11 REPLIES 11
Anonymous
Not applicable

@lbendlin , Many thanks for your readiness to help. I am attaching the tables and expected results to this post. Feel free to ask questions about the data you might have:

MikeMCFRS_1-1646662689863.png

 

Incident NumberDateAgeDispositionDescriptionLocationZIPPatient Name
G2100560101/1/201814SickCant walkAccra23345Baba,Kosi
G2100560111/2/201815Painsleep walkNairobi23346Melic,Konan
G2100560121/3/201816neck issuered stoolCapetown23347Babe,Roon
G2100560131/4/201817scratchesdiarhheaLusaka23348Musa,Traore
G2100560141/5/201818itchescoughBrazzaville23349Tonga,Managa
G2100560151/6/201819COPDCant walkAccra23350Haya,Wakubo

 

Full NameDOBDate of Review
Baba,Kosi8/16/19489/15/2021
Melic,Konan5/31/19859/15/2021
Tonga,Managa2/19/19819/15/2021

You say that date of enrollment is September 15, 2021 for all.  Your sample incident data only has calls before that date, and none of the calls are within six months.  

 

Without sample data that matches the request it is hard to come up with a meaningful proposal.

Anonymous
Not applicable

@lbendlin The incident data is such a huge one it will be tedious to mask the names and may not attach them as a file. What I was hoping is that we could use the sample to come up with a solution. What do you recommend??

If you like to get meaningful help you will want to provide meaningful sample data that fully covers your issue.

Anonymous
Not applicable

https://docs.google.com/spreadsheets/d/1T5yKwb0SDkwOzSsHukkekj5IcK4SAte9/edit?usp=sharing&ouid=10606... 

I have obtained a year worth of data. We can try 5 months before and maybe 3 months after. Let me know if the link works .

Thanks for your help

Hi @Anonymous ,

 

6 months before and after date of enrollment.

You need a table contains a column which used to be the Axis like line chart you provided. I create a table like this:

vchenwuzmsft_0-1646808828545.png

Then create a measure via this code:

Measure =
VAR _d =
    CALCULATE (
        SELECTEDVALUE ( Patients[Date of Review] ),
        ALLNOBLANKROW ( Patients )
    )
VAR _diff =
    SELECTEDVALUE ( 'Axis'[value] )
VAR _datestart =
    DATE ( YEAR ( _d ), MONTH ( _d ) + _diff, 1 )
VAR _dateend =
    DATE ( YEAR ( _d ), MONTH ( _d ) + _diff + 1, 1 ) - 1
RETURN
    IF (
        SELECTEDVALUE ( Patients[Full Name] ) = BLANK (),
        COUNTROWS (
            FILTER (
                ALL ( 'Calls' ),
                [Incident Date Time] >= _datestart
                    && [Incident Date Time] <= _dateend
            )
        ),
        COUNTROWS (
            FILTER (
                'Calls',
                [Incident Date Time] >= _datestart
                    && [Incident Date Time] <= _dateend
            )
        )
    )

Before you use this measure correctly, a relationship between calls and patients on name need to be created.

vchenwuzmsft_2-1646809758090.png

 

And result:

vchenwuzmsft_3-1646809799525.png

 

 

 

Best Regards!

Community Support Team _ chenwu zhu

 

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

Anonymous
Not applicable

@v-chenwuz-msft Many thanks for your suggestion solution and Dax. I will test it out and give you feedback soon.

I have two questions though:
1. Is there a way to arrange the DimMonth to have the negatives(Pre) on the left and the positives(Post) on the right of the chart.

2. Can I modify the Dax to only look at 5 months before and 3 months after and finally
3. Can I use the same dax formula if the Date of review is different for each patient? Please advise.

Thank You!!

 

Hi @Anonymous ,

 

Response of your questions.

2. The Axis table ( dimmonth ) was created by enter data, so just remove -6 month and others you do not want, but keep the [value] is right due to the [value] is identified as parameter for the DAX formula.

 

1. Sort the column(dimmonth) by [value] column.

vchenwuzmsft_0-1646879856331.png

 

3 If there are different review date for each patient, please use this code:

 

Measure =
VAR _diff =
    SELECTEDVALUE ( 'Axis'[value] )
VAR _s =
    SUMMARIZE (
        'Patients',
        Patients[Full Name],
        Patients[Date of Review],
        "COUNT",
            COUNTROWS (
                FILTER (
                    'Calls',
                    [Incident Date Time]
                        >= DATE ( YEAR ( EARLIER ( Patients[Date of Review] ) ), MONTH ( EARLIER ( Patients[Date of Review] ) ) + _diff, 1 )
                        && [Incident Date Time]
                            <= (
                                DATE ( YEAR ( EARLIER ( Patients[Date of Review] ) ), MONTH ( EARLIER ( Patients[Date of Review] ) ) + _diff + 1, 1 ) - 1
                            )
                )
            )
    )
RETURN
    SUMX ( _s, [COUNT] )

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

Anonymous
Not applicable

@v-chenwuz-msft I want to thank you for the solution you provided. It was really on point.

If I want to add 1yr+ to the Axis table, will it work??

 

Please advise

lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. If you paste the data into a table in your post or use one of the file services it will be easier to work with. Avoid posting screenshots of your source data if possible.

Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Anonymous
Not applicable

Greetings Sir,

 

I am following up on the formula you help me with earlier this year.

The formula has worked well so far but I have a new scenario I want to try to add to the chart:

 

When I select a patient to view their pre-post calls, I noticed that some patients do not have any calls after 3 months so the chart ends on the 3-month post. However, I would like that chart to show either a flat line or indicate zero calls so readers of the chat will know that the patient has stopped calling after, let's say, the 3rd month.

 So far I have tried to increase the Axis with two additional months after the 6-Month but it doesn't seem to be showing a flat line but rather the looking downwards.

 

Any ideas to tweak the formula to achieve this just like the picture I share earlier with you??

 

Your help is greatly appreciated.

 

Regards

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.