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.
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,
Solved! Go to Solution.
@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 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@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 🙂
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
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.
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,
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
42 | |
21 | |
21 | |
14 | |
13 |
User | Count |
---|---|
43 | |
39 | |
33 | |
18 | |
17 |