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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
kate_wass
New Member

Count of unique customer ID within date range - custom column?

Hi

 

I would love any advice to help me solve my problem statement.  As a relatively new person to Power BI I would love any advice you can provide.  I am looking to count on a record fort a call received today how many calls did that customer maki in the previous 7 days.  I have a dataset of calls over time, sample included below.  The unique customer ID is the phone number, the date range is the start date of the call minus 7 days.  

 

I think I want to solve this with a custome column, but open to any advice.  I am unsure whther the fact that my start date column includes time could be causing me issues?  Idealy I would want a solution that can consider the time of call as the customer may call multiple times in one day.  

 

For the sample I have provided below, I have provided the results I would expect for the calls received on the 08/01/22 based on the data supplied 01/01/22 - 08/01/22.

 

Thanks in advance for any support you can provide me.

 

Start date / timePhone numberHow many calls in previous 7 days
1/01/2022 8:0012345 
1/01/2022 9:0045678 
1/01/2022 10:0012345 
2/01/2022 10:0012345 
2/01/2022 11:0045678 
3/01/2022 8:0012345 
4/01/2022 8:0045678 
4/01/2022 9:0045678 
4/01/2022 10:0012345 
4/01/2022 11:0012345 
5/01/2022 9:0045678 
5/01/2022 10:0012345 
6/01/2022 10:0012345 
7/01/2022 11:0012345 
8/01/2022 8:00987650
8/01/2022 9:00123459
8/01/2022 10:00456785
8/01/2022 11:00456786
3 REPLIES 3
CNENFRNL
Community Champion
Community Champion

Excel worksheet formula is way powerful to solve such a simple question,

CNENFRNL_0-1646824782692.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

johnt75
Super User
Super User

This will calculate the number of calls in the previous 7 days

Num prev calls 7 days = 
var currentPhone = 'Table'[Phone number]
var currentDate = 'Table'[Start date / time]
return COALESCE( CALCULATE( COUNTROWS('Table' ), REMOVEFILTERS(), 'Table'[Phone number] = currentPhone
&& 'Table'[Start date / time] < currentDate && 'Table'[Start date / time] >= currentDate - 7 ), 0 )

Please note that this does take into account the time of the call, so the numbers returned are slightly different from your example. e.g. the last call for number 12345 occurs at 9am, so the first call on 1/1 at 8am is not included in the count as it falls outside the full 7 days.

If you want to include all calls which occurred upto 7 days ago, regardless of the time of the call, you could split your start date time column into separate date and time columns, or you could change the new column definition to just get the date part of currentDate - 7.

Jihwan_Kim
Super User
Super User

Hi,

I suggest having date column and time column separate.

And please wite the below calculated column to create a new column.

It will show the result for counting calls during previous seven days only for the dates that are after 8th Jan. 2022.

Please also check the attached pbix file.

 

Picture1.png

 

Calls in previous 7 days CC =
VAR currentphonenumber = Data[Phone number]
VAR currentdate = Data[Start date]
VAR sevendaysago = currentdate - 7
RETURN
    IF (
        Data[Start date] >= DATE ( 2022, 1, 8 ),
        COUNTROWS (
            FILTER (
                Data,
                Data[Phone number] = currentphonenumber
                    && Data[Start date] >= sevendaysago
                    && Data[Start date] < currentdate
            )
        ) + 0
    )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.