cancel
Showing results for 
Search instead for 
Did you mean: 

Sap Webi calculate the first and last assessments in the same day

Raz11
Explorer
0 Kudos
230

Hi Experts,

 

I have multiple assessments on the same day as (weight, blood pressure),

and I want to focus only on the first and last assessment of the day. see the first picture.

 

additionally, I want another formula to calculate the (height assessment) once for patient. see the second picture. there are 3 assessments for 1 patient, how to calculate it as once?

 

Regards.

View Entire Topic
radinator
Participant
0 Kudos

Hi Raz11,
since this is less of a technical problem and more of a coding problem let me give you my idea how your goal can be achieved:
First you need to have a way of getting the first and last entry for the current day. In order to get such a list you basically need to split the entire list per patient and order that list by the timestamp ascending which yields a sublist including all measurements for that patient. Next find the first and the last entry. Repeat this step for all patients.
Depending on what technology you are using (all done in OpenSQL or loading the entire medical database into one itab via OpenSQL and extracting the data for each patient into another itab via OpenSQL/ABAP your exact way of doing may differ.

One solution (may not be the most efficient one) is to do a SELECT on the medical database to get all data, a SELECT DISTINCT on the same but just for the patient Ids. Then loop over patient IDs and for each patient IDmake query against the medical itab where you fetch all the data associated with that patient and store them in a third iTab let's call it lt_patient_data. Get the length of that itab via data(lv_tab_size) lines( lt_patient_data). Finally you can access this table via index. Index [1] for the first element, Index [lv_tab_size] for the last entry (ABAP starts at 1 with indexing).

This code snippet should show my idea

 

 

" Get all data
select * from t005 into table (lt_t005).
  
" Get the primary key (PK)
select distinct land1 from t005 into table (lt_laender).
  
" Loop over all the PK values
loop at lt_laender into data(ls_land).
  
  " Query against the main db with the PK
  select * from _t005 as t where land1 = _land-land1 into table (lt_t005_02).
    
  " Get the table size
  data(lv_tab_size) = lines( lt_t005_02 ).
    
  " Retrieve the firs and the last row
  data(ls_first_row) = lt_t005_02[ 1 ].
  data(ls_last_row) = lt_t005_02[ lv_tab_size ].
  
  " Work with the data
  ls_first_row...
  
ENDLOOP. 

Edit: For the second question you have to be more specific what your goal is. Meaning what exactly you want to calculate. If you just want one of the like 3 values per patient per day then either first/last entry with indexing OR with a different subselect.

If your goal is to do the calculation of the say first entry for all patients with one SQL statement you should aim to first extract the first measurement per patient from the table and store those data in a second table and then iterate over that secondary table and do the calcs

 

Raz11
Explorer
0 Kudos
Thank you for your efforts; but I am using Sap Web intelligence, do you have another ideas??
radinator
Participant
0 Kudos
I am very sorry, but I am totally unfamiliar with SAP Web Intelligence, I have no idea how it works and what options you have. But I am very sure that my concept of how to do it, can be converted into whatever language you have at your hands when using SAP WebI. If you can tell me which languages are available I may be able to gives suggestions. GL!
radinator
Participant
0 Kudos
I found this 4 y/o YT tutorial about SAP BusinessObject Webi https://www.youtube.com/watch?v=YNQ3tY7eZDQ at around 40 minutes the person giving the talk is speaking about the input controls which allow some sort of SQL Input. Maybe you get lucky with this. Take the example of the talk, split it by the patient id instead of the year and try to find a FIRST() and LAST() functin to do the indexing part.
Raz11
Explorer
0 Kudos
Thank you. but the video not the same requirements