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
yve214
Helper III
Helper III

Please Urgent Help with Creating Period blocks from Start Date Column

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-easonf-msft
Community Support
Community Support

Hi, @yve214 

You can split the table into multiple sub-tables based on frequency_type, then convert each table rows into multiple interval rows for calculation and finally you can combine the results of multiple tables.

I made a sample (frequency type ="Monthly") for your reference.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFTSUQpOLEpUCAYyzPQNLfSNDIwMgGxDI31jQxjHCIiNgdg3P68kI6dSKVYHU7OhPlg5SMwYwQRhEyB2ytSFa44FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [patient_id = _t, patient_name = _t, start_date = _t, end_date = _t, expected_frequency = _t, frequency_code = _t, frequency_type = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"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}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([frequency_type] = "Monthly")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Month Span", each (12 * (Date.Year([end_date]) - Date.Year([start_date])))
+ (Date.Month([end_date]) - Date.Month([start_date]))
+ (if Date.Day([end_date]) < Date.Day([start_date]) 
    then -1 
    else 0
  )),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Month List", each List.Numbers(
  1,
  [Month Span]
)),
    #"Expanded Month list" = Table.ExpandListColumn(#"Added Custom1", "Month List"),
    #"Added Custom2" = Table.AddColumn(#"Expanded Month list", "from_date", each Date.AddMonths(
    [start_date],
     [Month List]-1
  )),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "to_date", each Date.AddDays(
Date.AddMonths( 
    [start_date], 
    [Month List] 
  ),-1)),
    #"Added Conditional Column" = Table.AddColumn(#"Added Custom3", "to_frequency_date", each if [Month Span] = [Month List] then [end_date] else [to_date]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"start_date", "end_date", "Month Span", "Month List", "to_date"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"patient_id", "patient_name", "from_date", "to_frequency_date", "expected_frequency", "frequency_code", "frequency_type"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"from_date", type date}, {"to_frequency_date", type date}})
in
    #"Changed Type1"
Actual frequency = 
CALCULATE (
    COUNT ( service_table[is_attended] ),
    FILTER (
        ALL(service_table),
        service_table[is_attended] = 1
            && service_table[date] >= 'frequency_table(monthly)'[from_date]
            && service_table[date] <= 'frequency_table(monthly)'[to_frequency_date]
    )
)
% Actual to Targe = 'frequency_table(monthly)'[Actual frequency]/'frequency_table(monthly)'[expected_frequency]

result:

veasonfmsft_3-1664455454129.png

 

Best Regards,
Community Support Team _ Eason

View solution in original post

1 REPLY 1
v-easonf-msft
Community Support
Community Support

Hi, @yve214 

You can split the table into multiple sub-tables based on frequency_type, then convert each table rows into multiple interval rows for calculation and finally you can combine the results of multiple tables.

I made a sample (frequency type ="Monthly") for your reference.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFTSUQpOLEpUCAYyzPQNLfSNDIwMgGxDI31jQxjHCIiNgdg3P68kI6dSKVYHU7OhPlg5SMwYwQRhEyB2ytSFa44FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [patient_id = _t, patient_name = _t, start_date = _t, end_date = _t, expected_frequency = _t, frequency_code = _t, frequency_type = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"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}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([frequency_type] = "Monthly")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Month Span", each (12 * (Date.Year([end_date]) - Date.Year([start_date])))
+ (Date.Month([end_date]) - Date.Month([start_date]))
+ (if Date.Day([end_date]) < Date.Day([start_date]) 
    then -1 
    else 0
  )),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Month List", each List.Numbers(
  1,
  [Month Span]
)),
    #"Expanded Month list" = Table.ExpandListColumn(#"Added Custom1", "Month List"),
    #"Added Custom2" = Table.AddColumn(#"Expanded Month list", "from_date", each Date.AddMonths(
    [start_date],
     [Month List]-1
  )),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "to_date", each Date.AddDays(
Date.AddMonths( 
    [start_date], 
    [Month List] 
  ),-1)),
    #"Added Conditional Column" = Table.AddColumn(#"Added Custom3", "to_frequency_date", each if [Month Span] = [Month List] then [end_date] else [to_date]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Conditional Column",{"start_date", "end_date", "Month Span", "Month List", "to_date"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"patient_id", "patient_name", "from_date", "to_frequency_date", "expected_frequency", "frequency_code", "frequency_type"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"from_date", type date}, {"to_frequency_date", type date}})
in
    #"Changed Type1"
Actual frequency = 
CALCULATE (
    COUNT ( service_table[is_attended] ),
    FILTER (
        ALL(service_table),
        service_table[is_attended] = 1
            && service_table[date] >= 'frequency_table(monthly)'[from_date]
            && service_table[date] <= 'frequency_table(monthly)'[to_frequency_date]
    )
)
% Actual to Targe = 'frequency_table(monthly)'[Actual frequency]/'frequency_table(monthly)'[expected_frequency]

result:

veasonfmsft_3-1664455454129.png

 

Best Regards,
Community Support Team _ Eason

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.

Top Solution Authors