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
Bokchoy
Helper II
Helper II

Count x based on periodid

Hi all,

 

I want to count the number of clients who have traded within this current period (15days) by periodid.

I have a jobs table and a calendar table. this is connected via 1:N relationship from calendar[single_dates] to jobs[Job_date]

 

Calendar table:                                      Jobs table:
Single_date    Periodid                             job_date                  job_ID                client_ID  
01/07/2021         1                               01/07/2021                  123123                   A
02/07/2021         1                               01/07/2021                  4234234                 A
...                                                                .....
16/07/2021         2

17/07/2021         2 

i've wrote a measure to retrieve the current periodid:

this period id = CALCULATE(SELECTEDVALUE(calendar[periodid]), calendar[SingleDate] = TODAY())
 
However my below measure does not work
calculate(distinctcount(job[client_id]), calendar[periodid] = this period id)

Could someone please give me a hand.
Thanks in advance.

 

 

 

1 ACCEPTED SOLUTION
v-luwang-msft
Community Support
Community Support

Hi @Bokchoy ,

A slight adjustment has been made to your second dax, see:

test = 
CALCULATE (
    DISTINCTCOUNT ( job[client_id] ),FILTER(ALL('calendar'),
    calendar[periodid] = [this period id]
))

And final show the below:

vluwangmsft_0-1627626814423.png

Wish it is helpful for you!

 

Best Regards

Lucien

View solution in original post

4 REPLIES 4
v-luwang-msft
Community Support
Community Support

Hi @Bokchoy ,

A slight adjustment has been made to your second dax, see:

test = 
CALCULATE (
    DISTINCTCOUNT ( job[client_id] ),FILTER(ALL('calendar'),
    calendar[periodid] = [this period id]
))

And final show the below:

vluwangmsft_0-1627626814423.png

Wish it is helpful for you!

 

Best Regards

Lucien

ryan_mayu
Super User
Super User

@Bokchoy 

does the this period id measure work?

could you pls provide more sample data and expected output?





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi Ryan,

 

Yes, the measure works. Right now the measure is returning "2" as we are in the second period. it should return "3" on the 1st of Aug.    (Fy start is 01/07 end is 30/06)

Unfortunately, i cant provide more sample data but I think the structure is pretty simple.


- the calendar table has every single day as an individual row from 07/2020 to 06/2022, grouped by period id and year. 

 

- the jobs table simply records when a client traded. Each row has a unique job_id, job_date, and other job information. there is no limit to how many jobs a client can trade each day.

 

@Bokchoy 

add a column in jobs table

period = RELATED('Calendar'[Period])

then create a measure

measure = CALCULATE(DISTINCTCOUNT(Jobs[cline_ID]),FILTER(Jobs,Jobs[period]= maxx(FILTER('Calendar','Calendar'[Single_date]=today()),'Calendar'[Period])))




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.