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.
Hi.
I have two tables - one has data in it relating to customers, incidents and dates. Some customers have multiple incidents so they can be in multiple rows of data. The other table shows movements of customers and the dates they moved. I want to add a new column to my first table which detects whether a customer has gone to hospital only (within movement column) for falls only (within incident column) within 2 days of the incident occurring. Example tables are below for current and expected data:
Current Data | ||||||
Table 1 | Table 2 | |||||
Customer Code | Incident | Date | Customer Code | Movement | Date | |
XYZ | Fall | 21/05/2021 | XYZ | Hospital | 23/05/2021 | |
XYZ | Burn | 9/04/2021 | XYZ | Hospital | 11/11/2020 | |
XYZ | Fall | 11/01/2021 | XYZ | Other | 9/09/2020 | |
ABC | Fall | 20/04/2021 | ABC | Other | 1/01/2021 | |
ABC | Laceration | 29/12/2020 | FGH | Hospital | 3/03/2021 | |
Expected Data | ||||||
Table 1 | ||||||
Customer Code | Incident | Date | Hospital within 2 days | |||
XYZ | Fall | 21/05/2021 | Yes | |||
XYZ | Burn | 9/04/2021 | No | |||
XYZ | Fall | 11/01/2021 | No | |||
ABC | Fall | 20/04/2021 | No | |||
ABC | Laceration | 29/12/2020 | No |
Solved! Go to Solution.
Hi, @NikkiSavage
Please check the below picture and the sample pbix file's link down below.
Hospital Within 2 days CC =
VAR currentcustomer = 'Table 1'[Customer Code]
RETURN
IF (
'Table 1'[Incident] = "Fall"
&& COUNTROWS (
FILTER (
'Table 2',
'Table 2'[Customer Code] = currentcustomer
&& 'Table 2'[Movement] = "Hospital"
&& 'Table 2'[Date] >= 'Table 1'[Date]
&& 'Table 2'[Date] <= 'Table 1'[Date] + 2
)
) > 0,
"Yes",
"No"
)
https://www.dropbox.com/s/leic0stepdpk5lj/nikki.pbix?dl=0
Hi, My name is Jihwan Kim.
If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.
Linkedin: linkedin.com/in/jihwankim1975/
Twitter: twitter.com/Jihwan_JHKIM
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
@NikkiSavage add new column using following expression:
Moved to Hospital in 2 days =
VAR __days = 2
VAR __incidentDate = Incident[Date]
RETURN
IF (
Incident[Incident] = "Fall" &&
CALCULATE (
COUNTROWS ( Movement ),
TREATAS ( VALUES ( Incident[Customer Code] ), Movement[Customer Code] ),
Movement[Date] >= __incidentDate,
Movement[Date] <= ( __incidentDate + __days )
),
"Yes",
"No"
)
Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
@NikkiSavage add new column using following expression:
Moved to Hospital in 2 days =
VAR __days = 2
VAR __incidentDate = Incident[Date]
RETURN
IF (
Incident[Incident] = "Fall" &&
CALCULATE (
COUNTROWS ( Movement ),
TREATAS ( VALUES ( Incident[Customer Code] ), Movement[Customer Code] ),
Movement[Date] >= __incidentDate,
Movement[Date] <= ( __incidentDate + __days )
),
"Yes",
"No"
)
Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Hi, @NikkiSavage
Please check the below picture and the sample pbix file's link down below.
Hospital Within 2 days CC =
VAR currentcustomer = 'Table 1'[Customer Code]
RETURN
IF (
'Table 1'[Incident] = "Fall"
&& COUNTROWS (
FILTER (
'Table 2',
'Table 2'[Customer Code] = currentcustomer
&& 'Table 2'[Movement] = "Hospital"
&& 'Table 2'[Date] >= 'Table 1'[Date]
&& 'Table 2'[Date] <= 'Table 1'[Date] + 2
)
) > 0,
"Yes",
"No"
)
https://www.dropbox.com/s/leic0stepdpk5lj/nikki.pbix?dl=0
Hi, My name is Jihwan Kim.
If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.
Linkedin: linkedin.com/in/jihwankim1975/
Twitter: twitter.com/Jihwan_JHKIM
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
97 | |
85 | |
70 | |
61 |
User | Count |
---|---|
151 | |
120 | |
103 | |
87 | |
68 |