Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Rngomoa
Frequent Visitor

grouping in a scalar value measure

Am trying to create a dashboard by counting the total patient_id (Greencard[patient_id]), for clients whose visit dates (Greencard[visit_date]) are less than the selected months (CalenderDate[dates]) and their visit dates are less than the exit date (Greencard[ExitDate1]).
 
 The first part of the dax works out fine. However, it has duplicates. So, my problem is the second part of the dax (i.e begining from COUNTX, which tries to remove those duplicates. Am getting an error. I would appreciate any assistance to remove the duplicates.
 
Thanks.
 
 
 
tx_curr =
var curdate=MAX(CalenderDate[dates])

var tx_curr2=CALCULATE(COUNT(Greencard[patient_id]),FILTER(Greencard,Greencard[visit_date]<=curdate && Greencard[visit_date]<=Greencard[ExitDate1]))

return

COUNTX(GROUPBY(Greencard,Greencard[patient_id],Greencard[mflcode],"Tx_curr3",maxx(CURRENTGROUP(),tx_curr2)),Greencard[patient_id])

 

1 ACCEPTED SOLUTION
BeaBF
Super User
Super User

@Rngomoa Hi!

The issue with the second part of your DAX formula is that the COUNTX function is trying to count the distinct patient IDs in the result of the GROUPBY function, but the GROUPBY function is not returning a table with distinct patient IDs because the MAXX function is being used as an aggregator.

 

tx_curr =
VAR curdate = MAX(CalenderDate[dates])
RETURN
COUNTX(
FILTER(
ADDCOLUMNS(
SUMMARIZE(
Greencard,
Greencard[patient_id],
Greencard[mflcode],
"tx_curr2", CALCULATE(COUNT(Greencard[patient_id]), Greencard[visit_date] <= curdate && Greencard[visit_date] <= Greencard[ExitDate1])
),
"tx_curr3", IF([tx_curr2] > 0, 1, 0)
),
[tx_curr3] > 0
),
DISTINCT(Greencard[patient_id])
)

 

BBF

View solution in original post

1 REPLY 1
BeaBF
Super User
Super User

@Rngomoa Hi!

The issue with the second part of your DAX formula is that the COUNTX function is trying to count the distinct patient IDs in the result of the GROUPBY function, but the GROUPBY function is not returning a table with distinct patient IDs because the MAXX function is being used as an aggregator.

 

tx_curr =
VAR curdate = MAX(CalenderDate[dates])
RETURN
COUNTX(
FILTER(
ADDCOLUMNS(
SUMMARIZE(
Greencard,
Greencard[patient_id],
Greencard[mflcode],
"tx_curr2", CALCULATE(COUNT(Greencard[patient_id]), Greencard[visit_date] <= curdate && Greencard[visit_date] <= Greencard[ExitDate1])
),
"tx_curr3", IF([tx_curr2] > 0, 1, 0)
),
[tx_curr3] > 0
),
DISTINCT(Greencard[patient_id])
)

 

BBF

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.