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
Landon1
New Member

I need help with writing a DAX measure for a kind of "cohort" analysis

Hello,

first I'm new here, I didn't find an opportunity to attach a pbix file, how is this possible?

 

My problem is the following: I have a data table, a simplified version looks like this.

Data table.png

 

Now I would like to have two filters in Power BI, I thought about two disconnected tables. They should allow to set a "Start Date" and an "End Date". Then I want to see, how the Customers have developed between Start and End date. The tricky part is, that I only want to compare the customers, that are available in the selected Start Date. The next screenshot shows a wrong result, but basically this is how I want to display it in Power BI:

PBI.png

The forumla for "End" is currently:

End =
VAR EndDate = MIN('End Date'[Date])
Return CALCULATE(DISTINCTCOUNT(Data[Customer]),FILTER(Data,Data[Date]=EndDate))

Now I would like to have a formula, which takes only the 2 customers selected for the Start (this is customer nr 1 and 2), and shows what the current Priority for these two customers is at the "End" Date. The right result would be (as customer 2 was Priority 4 in Jan 2000 and moved to Priority 1 in Jun 2000):

result.png

 

Would be really great to get some help here, I am already despairing and trying to solve the problem for a long time

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Landon1 ,

 

I suggest you to try this code to create a measure.

End =
VAR StartDate =
    MIN ( 'Start Date'[Date] )
VAR EndDate =
    MIN ( 'End Date'[Date] )
VAR LIST =
    CALCULATETABLE (
        VALUES ( Data[Customer] ),
        FILTER ( ALL ( Data ), Data[Date] = StartDate )
    )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Data[Customer] ),
        FILTER ( Data, Data[Date] = EndDate && Data[Customer] IN LIST )
    )

Result is as below.

RicoZhou_0-1678780009164.png

 

Best Regards,
Rico Zhou

 

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

1 REPLY 1
v-rzhou-msft
Community Support
Community Support

Hi @Landon1 ,

 

I suggest you to try this code to create a measure.

End =
VAR StartDate =
    MIN ( 'Start Date'[Date] )
VAR EndDate =
    MIN ( 'End Date'[Date] )
VAR LIST =
    CALCULATETABLE (
        VALUES ( Data[Customer] ),
        FILTER ( ALL ( Data ), Data[Date] = StartDate )
    )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( Data[Customer] ),
        FILTER ( Data, Data[Date] = EndDate && Data[Customer] IN LIST )
    )

Result is as below.

RicoZhou_0-1678780009164.png

 

Best Regards,
Rico Zhou

 

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.