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

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.

Reply
LijunChen
Resolver I
Resolver I

Dynamic DAX Measures to Generate Total Number of Rows / Records with Same/Duplicate Values

Dear All, 

I am analyzing a data with (children) client services records. The data 'service2018' listed the clients (cl_id) non-overlapping service episodes with service start and stop dates (start_x, stop_x). The data has also family id (fam_id) identifying whether the clients belong to the same family. 
I would like to create two Dax Measures:
a) total number of clients in service at any given date. 
b) total number of clients in any given date who has other family members (i.e., clients) in service at the same time. That is, total # of clients with 2 or more family members in service at the same date.
 
I have create date table 'Date_New'[Date] and linked its [Date] with service start date [start_x]. I would like to create a visual bar-chart of Total number of clients in service and number of clients with 2 or more family members across time (year/month). 
 
I have not problem with the 1st measure (clients in service at any date or beginning of date), which is as follows.
Measue_#inservice = CALCULATE (COUNTX (FILTER (service2018,service2018[start_x]<MIN('Date_New'[Date]) && service2018[stop_x]>=MIN('Date_New'[Date])),(service2018[cl_id])), CROSSFILTER(service2018[start_x],Date_New[Date],None))

But I cannnot figure out the correct DAX measure for the 2nd measure.

M_sibinservice = CALCULATE(COUNTX(FILTER(service2018,service2018[start_x]<MIN('Date_New'[Date]) && service2018[stop_x]>=MIN('Date_New'[Date]) && COUNTX(FILTER(service2018,EARLIER('service2018'[fam_id])='service2018'[fam_id]), 'service2018'[cl_id])>1), 'service2018'[cl_id]), CROSSFILTER(service[start_x],Date_New[Date],None))

In the above code, I use function EARLIER to generate the # of duplicates for each client/row, and filter in the rows with a value  greater than 1 together with the time filter. The measure can generate the summary values, but I don't think they are right because the final total count of clients with duplicate values are too many. I would be glad if I have your advice on how to solve this. Thanks.  

COUNTX(FILTER(service2018,EARLIER('service2018'[fam_id])='service2018'[fam_id]), 'service2018'[cl_id])>

 

3 REPLIES 3
LijunChen
Resolver I
Resolver I

Thanks for your reply. 

Here is an sample of the service records data that I have. 

cl_idfam_idepisode_numserv_seqprovider_idstart_xstop_xrace5cat
15492222019335021591586/19/20133/13/2014Black
15492222019335022155893/13/20144/23/2018Black
15492222019335023985194/23/20185/2/2018Black
15492222019335024155895/2/20186/1/2018Black
237918722228166712412761/16/20198/20/2019Black
1215291223556465124894612/14/201712/18/2018Other
6195703224609974251462812/7/201912/19/2019Other
5048033224609971125731412/7/20191/22/2020Other
2822470224609972225747312/19/20191/15/2020Other
3373233224609972225747312/19/20193/12/2020Other
282247022460997231189041/15/20201/23/2020Other
504803322460997122574731/22/20203/31/2020Other
282247022460997242574731/23/20203/31/2020Other
337323322460997231189043/12/20203/19/2020Other
337323322460997242574733/19/20203/31/2020Other
282247022460997252574733/31/20206/17/2020Other
842126622460997385149463/31/20207/9/2020Other
282247022460997262316196/17/20206/23/2020Other
282247022460997272574736/23/20207/9/2020Other
11243736224609975185326257/9/20207/13/2020Other
337323322460997272574737/13/20207/24/2020Other
7870503224609973145149467/13/20209/10/2020Other
337323322460997282511357/24/20209/16/2020Other
787050322460997316328769/10/202010/7/2020Other
337323322460997292457149/16/202010/15/2021Other
28224702246099721125837210/7/20202/22/2021Other
5048033224609971725837210/7/20208/6/2021Other
2822470224609972126402/22/20217/20/2021Other
2822470224609972132457147/20/202110/15/2021Other
504803322460997182646598/6/20211/24/2022Other
61957032246099742453193010/15/20215/1/2023Other
504803322460997192646591/24/20224/1/2022Other
5048033224609971102646594/1/20229/7/2022Other
151309522501511111245469/1/20119/13/2011Black
15130952250151112585219/13/20113/13/2017Black
151309522501511131014603/13/20177/17/2018Black
391664522565785425167823/5/20205/15/2020Other
391664522565785465167828/13/20201/29/2021Other
3916645225657854813161/29/20214/7/2021Other
10114652262265611164389/8/202011/20/2020White
6427775226280971126738312/17/20223/7/2023Other
642777522628097132656103/24/20235/1/2023Other
1011479226280971126593710/17/20211/10/2022White
101147922628097122659371/10/20227/11/2022White
1600860822636235337263451/17/20231/27/2023Black
1600860822636235368132101/27/20235/1/2023Black
267679922636235111088931/17/20231/27/2023Other
267679922636235122710701/27/20235/1/2023Other

 

What I would like to achieve is to create a dynamic measures to show (1) how many cl_id's are in service at any date based on 'start_x' and 'stop_x' (no overlapping service dates for any service record, but some are one follow the other); 2) how many cl_id's in service on any date have one other or more family members in service at the same time (based on family id 'fam_id'); and further, 3) how many of those with other family members in service at the same time have the same providers (provider_id).

Here is a screenshot of the visuals I created based on the first two measures I created with a date table linked to the service start date 'start_x'. But I don't think the numbers for the 2nd measure are corrected caculated. 

LijunChen_0-1684449551541.png

Your advice is appreciated. 

 

     

v-zhangti
Community Support
Community Support

Hi, @LijunChen 

 

Can you provide sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures or Excel.

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I have provided some sample data in the post above. Appreciate if you can help.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors