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
Silver75
Frequent Visitor

number of customer

Hi

I have my FACTS table with

ID

DATE

PRODUCT

 

I would like to calculate the number of customer that have bought from first date and last date -365 days, all history except last 365 days. My date field is not contiguous and dateadd doesn't work

 

Could you help me to wrtite this measure in DAX, please?

Thanky you  

5 REPLIES 5
v-yulgu-msft
Employee
Employee

Hi @Silver75,

 

What did you mean "customer that have bought from first date and last date -365 days"? Please elaborate your requirement with detailed data and screenshot of desired output.

 

Below is the test based on my assumption.

 

 

To work around the limitation of noncontiguous date, we should create a calendar table. And create a calculated column to get the date 365 days ago.

Date table = CALENDAR(DATE(2015,1,1),DATE(2017,12,31))
Last date-365 = DATEADD('Date table'[Date].[Date],-365,DAY)

Data view. [First date], [Last date] and [Last date -365] are calculated columns I added to source table, in order to understand steps clearly. Actually, there is no need to add them to source table.

1.PNG

 

I used below measure formula to count the customer.

measure =
CALCULATE (
    DISTINCTCOUNT ( FACTS[ID] ),
    FILTER (
        FACTS,
        CALCULATE ( MIN ( FACTS[DATE] ), ALLEXCEPT ( FACTS, FACTS[ID] ) )
            <= LOOKUPVALUE (
                'Date table'[Last date-365],
                'Date table'[Date], CALCULATE ( MAX ( FACTS[DATE] ), ALLEXCEPT ( FACTS, FACTS[ID] ) )
            )
    )
)

The result of this measure is 1.

 

Regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yulgu-msft,

than you

variabiles in FACTS: ID, DATE; PRODUCT; SALES

each customer ID has an history of sales similar your table without First Date e Last Date column.

Selecting a Year (or period) I need to calculate sales to date, eg Sales in the year in exam,  and all sales histroy except last 365 days from last date order -365 day, that is all order (all customer) from first data to  "my last data"  = (last data real of bought -365 days)

Hi @Silver75,

 

I have mentioned before, [First date], [Last date] and [Last date -365] are calculated columns I added to source table, in order to understand steps clearly. Actually, there is no need to add them to source table.

 

According to current description, "(all customer) from first data to  "my last data"  = (last data real of bought -365 days)", so, you want to calculate how many customers has bought over one year, right? If so, based on my original post, we can get this desired number.

 

If I have something misunderstood, please correct me. Please elaborate your requirement with examples. What is your desired output based on the sample data I provided above?

 

Regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

thank you for your support

I solved with a new dimension in SQL

 

Hi @Silver75,

 

Glad to hear that you have achieved your requirement. Thanks for your sharing.

 

Regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider 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.