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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Joana_
Regular Visitor

DAX: Create a column where I count frequency based on date range from another table

I am really struggling with this one - hoping some one can help me.

I want to count for each customer the number of months. I have two key tables:

 

Tabel_10 :

- Customer

- Customer_Group

- Date

- Date_L12

 

Tabel_9

- Customer

- Customer_Group

- Date

 

The two table are joined by the key "Customer".

 

So what I want, is that:

for each customer in table_10 I want to see how many times he appears in table_9 between the data range tabel_10[Date] & Table_10[Date_L12]

 

 

 

So what I want is a new column "Frequency" in Tabel_10. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Joana_ ,

I created some data:

Table_9:

vyangliumsft_0-1683598707578.png

Table_10:

vyangliumsft_1-1683598707579.png

 

Here are the steps you can follow:

1. Create calculated column.

Flag =
var _table10=
SELECTCOLUMNS('Table_10',"1",[Customer])
var _if=
IF(
    'Table_9'[Customer] in _table10
    &&
 'Table_9'[Date]>=MAXX(FILTER(ALL(Table_10),'Table_10'[Customer]=EARLIER('Table_9'[Customer])),[Date])
    &&
    'Table_9'[Date]<=MAXX(FILTER(ALL(Table_10),'Table_10'[Customer]=EARLIER('Table_9'[Customer])),[Date_L12])
    ,1,0)
return
_if
Column =
COUNTX(
    FILTER(ALL(Table_9),
    'Table_9'[Flag]=1),[Customer])

 2. Result:

vyangliumsft_2-1683598761160.png

 

Best Regards,

Liu Yang

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @Joana_ ,

I created some data:

Table_9:

vyangliumsft_0-1683598707578.png

Table_10:

vyangliumsft_1-1683598707579.png

 

Here are the steps you can follow:

1. Create calculated column.

Flag =
var _table10=
SELECTCOLUMNS('Table_10',"1",[Customer])
var _if=
IF(
    'Table_9'[Customer] in _table10
    &&
 'Table_9'[Date]>=MAXX(FILTER(ALL(Table_10),'Table_10'[Customer]=EARLIER('Table_9'[Customer])),[Date])
    &&
    'Table_9'[Date]<=MAXX(FILTER(ALL(Table_10),'Table_10'[Customer]=EARLIER('Table_9'[Customer])),[Date_L12])
    ,1,0)
return
_if
Column =
COUNTX(
    FILTER(ALL(Table_9),
    'Table_9'[Flag]=1),[Customer])

 2. Result:

vyangliumsft_2-1683598761160.png

 

Best Regards,

Liu Yang

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

Joana_
Regular Visitor

P.S. the column about the "Date" are based on months.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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