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
mmp
Helper I
Helper I

Help on calculating a measure when selecting a specific date

Hello,

 

I am trying to calculate a measure that gives me the number of client that have bought from day -59 to -40 (depending on selection date) and have not bought during the last 30 days.

 

I searched on the forum and found something that inspired me and I adapted it in order to fit the required conditions

:

 

 

test = 

var tday = IF(HASONEVALUE(BIDAT[DAT_mois_nom]),FIRSTDATE(BIDAT[DAT_date]))
VAR day_30 = FIRSTDATE(DATEADD(BIDAT[DAT_date],-30,DAY))
VAR day_40 = FIRSTDATE(DATEADD(BIDAT[DAT_date],-40,DAY))
VAR day_59 = FIRSTDATE(DATEADD((BIDAT[DAT_date]),-59,DAY))

RETURN
COUNTROWS (
    FILTER (
        ADDCOLUMNS (
            VALUES ( BITKT[TKT_NUMCARTE] ),
            "Purchase_Between_40_59", CALCULATE (
                COUNTROWS ( BITKT ),DATESBETWEEN(BIDAT[DAT_date],day_59,day_40),ALLEXCEPT( BICLID,BICLID[CLID_mobile],BICLID[CLID_NOM],BICLID[Alea])
            ),
            "Last30DaysPurchase", CALCULATE (
                COUNTROWS ( BITKT ),DATESBETWEEN(BIDAT[DAT_date],day_30,tday),ALLEXCEPT( BICLID,BICLID[CLID_mobile],BICLID[CLID_NOM],BICLID[Alea])
            )
        ),
        [Purchase_Between_40_59] <> 0
            && [Last30DaysPurchase] = 0
    )
)

 

 

It works when I select a month however when I try to select a specific date it shows Blank value.

 

Could you help me and tell me what I did wrong ?

 

Kind regards,

 

Mohammad

1 ACCEPTED SOLUTION

@mmp 

 

IF(HASONEVALUE(BIDAT[DAT_mois_nom])
You have used month in the if condition, try change it to [Date_date] column.

 

 
Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
lbendlin
Super User
Super User

Can you please show your data model and the structure of the BIDAT table?

Hello @lbendlin

 

Here it is : 

 

Capture d’écran 2020-11-08 à 20.07.35.png

 

It's a basic calendar table.

 

Kind regards,

 

Mohammad

@mmp 

 

IF(HASONEVALUE(BIDAT[DAT_mois_nom])
You have used month in the if condition, try change it to [Date_date] column.

 

 
Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

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.