Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I have this SQL:
WITH
Arytmi AS (
SELECT
ResponderId,
AnswerId = SvarHjertelinjenKey
FROM [dm].[FactHjertelinjen]
where
Kilde = 'Hjertelinjen Forms'
AND SvarHjertelinjenKey = 1000010
),
Guide AS (
SELECT
ResponderId,
AnswerId = SvarHjertelinjenKey
FROM [dm].[FactHjertelinjen]
where
Kilde = 'Hjertelinjen Forms'
AND SvarHjertelinjenKey IN (1000048,1000050)
)
SELECT
a.ResponderId,
HeartFailure = a.AnswerId,
DirectedToOwnDoctor = MAX(CASE WHEN g.AnswerId IN (1000048) THEN g.AnswerId ELSE NULL END),
DirectedToMedicalCenter = MAX(CASE WHEN g.AnswerId IN (1000050) THEN g.AnswerId ELSE NULL END)
FROM Arytmi a
JOIN Guide g ON a.ResponderId = g.ResponderId
GROUP BY
a.ResponderId,
a.AnswerId
order by
1
The SQL finds in the first CTE the ResponderId who has a certain HeartFailure. The next CTE looks for ResponderId's That has been sent to either own doctor or Medical center. I then compare to get a list a responderId's that has the specific heartfailure and been sent to both or either places - The reason for the Max in SQL
What would the measure in DAX look like?
I guess it can be done but I can't figure it out 🙂
Output expected:
ResponderId HeartFailure DirectedToOwnDoctor DirectedToMedicalCenter
1000097 1000010 NULL 1000050
1000103 1000010 NULL 1000050
1000115 1000010 1000048 NULL
1000117 1000010 1000048 NULL
1000118 1000010 1000048 NULL
1000121 1000010 1000048 NULL
1000134 1000010 1000048 NULL
1000144 1000010 1000048 1000050
1000156 1000010 1000048 NULL
1000158 1000010 NULL 1000050
1000161 1000010 NULL 1000050
1000166 1000010 1000048 NULL
1000167 1000010 1000048 1000050
1000179 1000010 1000048 NULL
1000189 1000010 1000048 NULL
1000193 1000010 1000048 NULL
1000194 1000010 1000048 NULL
Can you explain the Expected Output?
Did I answer your question? If so, please mark my post as a solution!
Proud to be a Super User!
The output gives me one responderId for the Heartfailure which is only one answer - Arytmi in the CTE
In the Guide CTE I look for ResponderId for to Answers - DirectedToOwnDoctor or DirectedToMedicalCenter
Finally I Join the two to get only one ResponderId for the Arytmi and one line with either DirectedToOwnDoctor or DirectedToMedicalCenter or both.
The result is used to show how many heartfailures are send to DirectedToOwnDoctor or DirectedToMedicalCenter and by that I can or hope to create a Count on ResponderId.
Does that make sense?
Try with Count(table[ResponderId])
Did I answer your question? If so, please mark my post as a solution!
Proud to be a Super User!
That would have been easy and I could have figured that out myself. It is a questionary where the respondent answers several questions while we are talking to he/she. One question is the Heartfailure type with an answerId. The other question is about the guidians to doctor etc. and comes from the same questionary but I need the cross reference between the two answers and the corresponding ResponderId.
If you provide logic or concept behind this query or dummy expected output then may be we can achieve this
Did I answer your question? If so, please mark my post as a solution!
Proud to be a Super User!
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
73 | |
72 | |
39 | |
31 | |
26 |
User | Count |
---|---|
97 | |
87 | |
43 | |
40 | |
35 |