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
Anonymous
Not applicable

Dynamic Flag on dates based on a date slicer

Hello, 

 

I'm stuck cause of a condition I fail to apply in DAX. 

 

In my FactTable, I have customers (NAME), amount and date of purchase.

 

CUSTOMER        DATE

alexis                  22/09/2017

alexis                  24/05/2016

charle                22/10/2017                  

bea                   04/06/2016

 

 

I have a CalendarTable which is related to the FactTable DATE <=> DATE OF PURCHASE

 

On my screen, I'll have a relative date slicer (with my 'Calendar'[Date]).
If my MIN(DATE) is, for example, 19/10/2017, I would like to count all the customers who have purchased something in 2017 and in 2016.

 

The management rule is :

Count the number of customers who have make at least one purchase the selected year (N) and at least one purchase the previous year (N-1). 

 

 

 

My problem is I do not achieve to flag this ! I can't use a calculated column because it is based on a dynamic filter but how can I filter it ? 

 

 

I tried :

VAR SelectedYear = YEAR( MIN (Calendar[Date]))

VAR PreviousSelectedYear = YEAR( MIN (Calendar[Date]))-1

 

RETURN

CALCULATE (

DISTINCTCOUNT (FactTable[Customer] ; 

FILTER ( YEAR (MAX (FactTable[Date of purchase] = SelectedYear ) && 

YEAR (MAX (FactTable[Date of purchase] = PreviousSelectedYear )))

 

 

But it doesn't work because I'm using the MAX function. 


How can I "scan" all of my date based on a dynamic slicer ? 

 

 

Thanks by advance for ur help,

 

 

1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@Anonymous 

I have created a measure that you can use to filter customers who purchased at least once in current asn last year. you can assing it to visual filter or modify with amount.

You can download the file: HERE



 

Measure = 
VAR CY =  YEAR(MIN('Calendar'[Date]))
VAR LY =  YEAR(MIN('Calendar'[Date]))-1

VAR CYCUST = 
    CALCULATETABLE(
        VALUES('Fact Table'[Customer]),
        'Calendar'[Year #] = CY,
        ALL('Calendar')
    )
VAR LYCUST = 
    CALCULATETABLE(
        VALUES('Fact Table'[Customer]),
        'Calendar'[Year #] = LY,
        ALL('Calendar')
    )
RETURN

IF(
    COUNTROWS(INTERSECT( CYCUST , LYCUST )) > 0,
    1,
    0
)

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

 

 

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@Anonymous 

I have created a measure that you can use to filter customers who purchased at least once in current asn last year. you can assing it to visual filter or modify with amount.

You can download the file: HERE



 

Measure = 
VAR CY =  YEAR(MIN('Calendar'[Date]))
VAR LY =  YEAR(MIN('Calendar'[Date]))-1

VAR CYCUST = 
    CALCULATETABLE(
        VALUES('Fact Table'[Customer]),
        'Calendar'[Year #] = CY,
        ALL('Calendar')
    )
VAR LYCUST = 
    CALCULATETABLE(
        VALUES('Fact Table'[Customer]),
        'Calendar'[Year #] = LY,
        ALL('Calendar')
    )
RETURN

IF(
    COUNTROWS(INTERSECT( CYCUST , LYCUST )) > 0,
    1,
    0
)

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, LinkedIn

 

 

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

lbendlin
Super User
Super User

You don't want to use your dates table for the slicer. Instead, create a calculated table that has just the date column from your dates table (via VALUES()) and feed the slicer from there.   Then you can create a measure that pulls the SELECTEDVALUE() from the slicer and does the required date math.

Anonymous
Not applicable

Thanks for answering but I don't understand your point. My problem is that I want to check multiple values on a single column, group by customers. 

I tried your solution but this doesnt change anything to my measure's problem..

Can you maybe explain to me more deeply tour thought ? 

 

 

Thx by advance,

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.

Top Solution Authors