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.
Good morning, everyone,
I have a Power BI data called PolicyData which is imported from SQL dataset PoicyData. IT department gave me the SQL code to get unique count as shown below.
I tried days to write a Measure with Calculated Column and earlier DAX to try to get the count but failed.
I appreciate your help to “translate” this SQL code into a Power BI measure.
Dennis
select count(distinct Claimant)
from PolicyData f1
where
Account_Date >= '2019-01-01' and
Claimant not in
(select Claimant from PolicyData where
Account_Date >= '2019-01-01' and Record_Type = 'P') and
Claimant in
(select Claimant
from PolicyData
where Account_Date < '2019-05-01'
group by Claimant having sum(Amount) = 0
) ;
Solved! Go to Solution.
Hi, Pattem,
I added one more criteria [TRASN_TYPE] = “INDEM” and tested the all the situations but changing NOT in differetn filtering colujmns but still got the number which is higher than the SQL result (the unique count is 923). The lowest number based on your code is 1,619.
Had a chance, could you take a look?
Appreciate your help.
Dennis
L16 CWOP DistinctCount =
VAR Exclusion =
SELECTCOLUMNS (
FILTER (
LossFile,
LossFile[RECORD_TYPE] = "P"
&& LossFile[TRANS_TYPE] = "INDEM"
&& LossFile[ACCOUNT_DATE] >= DATE ( 2019, 1, 1 )
),
"CLAIMANT", LossFile[CLAIMANT]
)
VAR Inclusion =
SELECTCOLUMNS (
FILTER (
SUMMARIZE (
FILTER (
LossFile,
LossFile[TRANS_TYPE] = "INDEM"
&& LossFile[ACCOUNT_DATE] < DATE ( 2019, 5, 1 )
),
LossFile[CLAIMANT],
"Total", SUM ( LossFile[AMOUNT] )
),
[Total] = 0
),
"CLAIMANT", LossFile[CLAIMANT]
)
RETURN
CALCULATE (
DISTINCTCOUNT ( LossFile[CLAIMANT] ),
FILTER (
LossFile,
(LossFile[CLAIMANT]) IN Exclusion
&& NOT(LossFile[CLAIMANT]) IN Inclusion
)
)
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 |
---|---|
111 | |
100 | |
80 | |
64 | |
58 |
User | Count |
---|---|
146 | |
110 | |
93 | |
84 | |
67 |