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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
yve214
Helper III
Helper III

Please Urgent Help with Creating Period blocks from Start Date

Hello,

 

Please, I desperately need help with any tips or recommendations on how to target this problem.

 

I have one requirement in a cencus report I built to add actuals to target services of patients. What I mean by this is,

 

if I have a patient who is required to have their services done 2 times monthly, I would hope from the start date to 30 days from that start date, they have been attended to, 2 times giving me 100% of my actual to target.

 

So again, if my expected services to be done is set to be 2 services monthly, my actual services in that time period from the start date e.g. 1/1/2022 - 1/31/2022  is 1, then that I would have been attended to just 50% of the time. 

 

Is there a way anyone could advise me how to target this problem given the below data, and if so, would you recommend some ideas please? I really need help with how I can build some of this period blocks so if its

- monthly, +30 days from start date

- weekly, +14 days from start date

-bi-monthly, +60 days from start date

- quarterly, +90 days from start date and so on

 

I had to model both of these fact tables in power bi. I can also perform a join in the database to merge all to one, of which I plan to do. Its just a bit challenging considering the frequency table has a start & end date, and the service table has just a calendar date. I guess I can join both tables on their patient_id and service_date where it falls between the from and to date columns in the frequency table.

 

But please advise, anything would be greatly appreciated. I really need inputs on how to get this one visual out. THANK YOU so much in advance.

 

Sample raw data

frequency_table:

patient_idpatient_namestart_dateend_dateexpected_frequencyfrequency_codefrequency_type
1001Sara S6/18/202012/31/202023Monthly
1001Sara S1/1/20213/1/202114Bi-Monthly

 

service_table: is_attended code 1 for Yes, 0 for No. 

patient_idpatient_namedateis_attended
1001Sara S6/18/20201
1001Sara S6/30/20201
1001Sara S7/18/20201
1001Sara S7/31/20200
1001Sara S8/18/20201
1001Sara S8/31/20200
1001Sara S9/18/20201
1001Sara S9/30/20211
1001Sara S10/18/20211
1001Sara S10/29/20211
1001Sara S11/18/20210
1001Sara S12/5/20210
1001Sara S12/18/20210
1001Sara S12/27/20210
1001Sara S1/1/20211
1001Sara S2/1/20210
1001Sara S3/15/20210

 

Expected Results: to_frequency_date is a sample column for the period date from the frequency "start_date". 

patient_idpatient_namefrom_dateto_frequency_dateexpected_frequencyActualfrequency_type% Actual to Target(freq)
1001Sara S6/18/20207/17/202022Monthly100%
1001Sara S7/18/20208/17/202021Monthly50%
1001Sara S8/18/20209/17/202021Monthly50%
1001Sara S9/18/202010/17/202022Monthly100%
1001Sara S10/18/202011/17/202022Monthly100%
1001Sara S11/18/202012/17/202020Monthly0%
1001Sara S12/18/202012/31/202010Monthly0%
1002Sara S1/1/20213/1/202111Bi-Monthly100%

 

Please let me know if you have any questions, happy to clarify.

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

Hi, @yve214 

According to your description , you want to display the visual you provide in the last of this article.

For the output data you provide, I found that every date interval was inconsistent, some 30 days and some 29 days.One thing to be clear is that we have to make sure that this date interval is consistent, and here I test it according to the rules you provide (14, 30, 60, 90).

Here are the steps you can follow:

(1)This is my test data: ‘Sheet1’ and 'Sheet4'

vyueyunzhmsft_0-1664436543867.png

vyueyunzhmsft_1-1664436553414.png

(2)We can extend the table 'Sheet1' in Power Query Editor:

let
    Source = Excel.Workbook(File.Contents("C:\Users\v-yueyzhang\Downloads\case\case.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    test = Table.TransformColumnTypes(#"Promoted Headers",{{"patient_id", Int64.Type}, {"patient_name", type text}, {"start_date", type date}, {"end_date", type date}, {"expected_frequency", Int64.Type}, {"frequency_code", Int64.Type}, {"frequency_type", type text}}),
    #"Added Custom1" = Table.AddColumn(test, "frequency_days", (x)=> if x[frequency_type] = "Monthly" then 30 else if x[frequency_type] = "Bi-Monthly" then 60 else if  x[frequency_type]="Weekly" then 14 else  90),
    #"Added Custom" = Table.AddColumn(#"Added Custom1", "Series", (x)=> Table.AddColumn(Table.FromColumns({List.Dates( x[start_date] ,Number.RoundUp(Number.From((x[end_date]-x[start_date])/x[frequency_days])), #duration(x[frequency_days],0,0,0) )}),"end",(y)=>if Date.From(Number.From(y[Column1])+29) > x[end_date] then x[end_date] else Date.From(Number.From(y[Column1])+x[frequency_days]-1)    )                   ),
    #"Expanded Series" = Table.ExpandTableColumn(#"Added Custom", "Series", {"Column1", "end"}, {"from_date", "to_frequency"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Series",{{"from_date", type date}, {"to_frequency", type date}})
in
    #"Changed Type"

The result in Power Query Editor is :

vyueyunzhmsft_2-1664436725749.png

(3)Then we Apply it to Power BI Desktop, we can create two measures :

Actual = var _current_id=SELECTEDVALUE('Sheet1'[patient_id])
var cuurent_from=SELECTEDVALUE('Sheet1'[from_date])
var current_to=SELECTEDVALUE('Sheet1'[to_frequency])
var _t=FILTER('Sheet4','Sheet4'[patient_id]=_current_id && 'Sheet4'[date] >= cuurent_from && 'Sheet4'[date] <= current_to && 'Sheet4'[is_attended]=1)
return 
COUNTROWS(_t)+0
% Actual to Target(freq) = DIVIDE(  [Actual]  , SUM('Sheet1'[expected_frequency]))

(4)Then we can put the measures and the fields in the visual we need so that we can meet your need, the result is as follows:

vyueyunzhmsft_3-1664436835766.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

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

1 REPLY 1
v-yueyunzh-msft
Community Support
Community Support

Hi, @yve214 

According to your description , you want to display the visual you provide in the last of this article.

For the output data you provide, I found that every date interval was inconsistent, some 30 days and some 29 days.One thing to be clear is that we have to make sure that this date interval is consistent, and here I test it according to the rules you provide (14, 30, 60, 90).

Here are the steps you can follow:

(1)This is my test data: ‘Sheet1’ and 'Sheet4'

vyueyunzhmsft_0-1664436543867.png

vyueyunzhmsft_1-1664436553414.png

(2)We can extend the table 'Sheet1' in Power Query Editor:

let
    Source = Excel.Workbook(File.Contents("C:\Users\v-yueyzhang\Downloads\case\case.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    test = Table.TransformColumnTypes(#"Promoted Headers",{{"patient_id", Int64.Type}, {"patient_name", type text}, {"start_date", type date}, {"end_date", type date}, {"expected_frequency", Int64.Type}, {"frequency_code", Int64.Type}, {"frequency_type", type text}}),
    #"Added Custom1" = Table.AddColumn(test, "frequency_days", (x)=> if x[frequency_type] = "Monthly" then 30 else if x[frequency_type] = "Bi-Monthly" then 60 else if  x[frequency_type]="Weekly" then 14 else  90),
    #"Added Custom" = Table.AddColumn(#"Added Custom1", "Series", (x)=> Table.AddColumn(Table.FromColumns({List.Dates( x[start_date] ,Number.RoundUp(Number.From((x[end_date]-x[start_date])/x[frequency_days])), #duration(x[frequency_days],0,0,0) )}),"end",(y)=>if Date.From(Number.From(y[Column1])+29) > x[end_date] then x[end_date] else Date.From(Number.From(y[Column1])+x[frequency_days]-1)    )                   ),
    #"Expanded Series" = Table.ExpandTableColumn(#"Added Custom", "Series", {"Column1", "end"}, {"from_date", "to_frequency"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Series",{{"from_date", type date}, {"to_frequency", type date}})
in
    #"Changed Type"

The result in Power Query Editor is :

vyueyunzhmsft_2-1664436725749.png

(3)Then we Apply it to Power BI Desktop, we can create two measures :

Actual = var _current_id=SELECTEDVALUE('Sheet1'[patient_id])
var cuurent_from=SELECTEDVALUE('Sheet1'[from_date])
var current_to=SELECTEDVALUE('Sheet1'[to_frequency])
var _t=FILTER('Sheet4','Sheet4'[patient_id]=_current_id && 'Sheet4'[date] >= cuurent_from && 'Sheet4'[date] <= current_to && 'Sheet4'[is_attended]=1)
return 
COUNTROWS(_t)+0
% Actual to Target(freq) = DIVIDE(  [Actual]  , SUM('Sheet1'[expected_frequency]))

(4)Then we can put the measures and the fields in the visual we need so that we can meet your need, the result is as follows:

vyueyunzhmsft_3-1664436835766.png

 

If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.

 

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

 

 

 

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

August Carousel

Fabric Community Update - August 2024

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