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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
CLQ
Helper I
Helper I

Calculate all repeated values ​​within a certain time

Hi everyone. I have a table like this:

Date||User||Region||Country||First Order Europe||First Order Asia||Cohort 
01/01/2022||Carl||America||Bolivia||False||False||202201
01/02/2022||Carl||Europe||Spain||True||False||202202
01/03/2022||Carl||Asia||China||False||True||202203
05/03/2022||Carl||Asia||Vietnam||False||True||202203
06/03/2022||Carl||Europe||Italy||False||False||202203

 

So, in a matrix whose rows are the "Cohort" column and the columns are the Date column in day format, I want to see the number of users who bought twice (=2), in 30 days or less, by region, example, Region = Asia

 

I managed to do it by creating more columns and a measure, but my problem with the current logic is that if I then want to add a Slicer, for example by country, the results give me incorrect results (in my case, there were rows where my column was =2 but it was because the user bought twice in the region, not necessarily in the same country). So I'm looking for something more dynamic, ie putting everything in a measure, but currently I couldn't manage to do it.

 

I tried to do it by trying calculations whose base is: 

Measure = 
var min_date = MIN(Table[Date])
var max_date = min_date+30
return
CALCULATE(
    COUNTROWS( 'Table' ),
    ALLSELECTED( 'Table' ),
    VALUES( 'Table'[User] ),
    FILTER(Table, MIN(Table[Date])>=min_date && MIN(Table[Date])<=max_date)
)=2

 

 

But this kind of logic throws me the error that I don't have enough memory or the results are wrong. If anyone comes up with another way, I appreciate it!

Thanks 

2 REPLIES 2
jaweher899
Impactful Individual
Impactful Individual

Please try

 

Measure =
VAR UserList =
CALCULATE(
DISTINCTCOUNT(Table[User]),
FILTER(
ALL(Table),
Table[Region] = SELECTEDVALUE(Table[Region]),
Table[First Order Asia] = True,
MIN(Table[Date])<Table[Date]+30
)
)
RETURN
CALCULATE(
COUNT(Table[User]),
FILTER(
Table,
Table[User] IN UserList,
Table[Region] = SELECTEDVALUE(Table[Region]),
Table[First Order Asia] = True,
MIN(Table[Date])<Table[Date]+30
)
) / 2

First, thanks for answering 🙂 . It doesn't work for me, changing the commas to "&&", I have problems with the "In" operator since it throws me an error. Even if I put the variable inside { }, I get the following error:

CLQ_0-1675258673043.png

Edit: I forgot to comment that this is because the calculation in the variable is a distinctcount. I replace it with a "values" but I get the out of memory error 😔

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors