Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Im trying to use a measure in a DAX filter to count the numbers of customers for each Key Account Manager (KAM) at a given date, but it does not seem to work.
My measure is calculated like this, and gives me the dateID for the end of the completed month which is two completed months ago (in january, last date of october previous year etc). M_MaxDateID is the latest dateID in Sales.
M_StartDate2MonthsInterval =
VAR SlicerDate = MAX('Sales'[DateID] )
RETURN CALCULATE(max('Sales'[DateID])
, Filter(ALL('Sales'[DateID]), IF(VALUE(MID([M_MaxDateID],5,2))<2,'Sales'[DateID] <= (SlicerDate-200),'Sales'[DateID] <= (SlicerDate-9000))))
When I put these measure on a card, I see the values I want, i.e. today it's 20221031 for M_StartDate2MonthsInterval and 20230130 for M_MaxDateID.
But then I try to put M_StartDate2MonthsInterval in a Filter in another Measure it fails.
This measure is blank:
M_NumberOfCustomersTwoMonthsAgo = CALCULATE(DISTINCTCOUNT('Sales'[CustomerID]),'Sales'[KAM_email]="someone@mycompany.com",'Sales'[DateID] = [M_StartDate2MonthsInterval]))
If I instead put in the value I know M_StartDate2MonthsInterval holds (20221031), I get my number of customers of 20221031:
M_NumberOfCustomersTwoMonthsAgo = CALCULATE(DISTINCTCOUNT('Sales'[CustomerID]),'Sales'[KAM_email]="someone@mycompany.com",'Sales'[DateID] = 20221031))
Why can't I put the measure in a filter?
Regards,
John Martin
Solved! Go to Solution.
Does it work if you store the result of the measure in a variable ?
M_NumberOfCustomersTwoMonthsAgo =
VAR ReferenceDate = [M_StartDate2MonthsInterval]
RETURN
CALCULATE (
DISTINCTCOUNT ( 'Sales'[CustomerID] ),
'Sales'[KAM_email] = "someone@mycompany.com",
'Sales'[DateID] = ReferenceDate
)
Does it work if you store the result of the measure in a variable ?
M_NumberOfCustomersTwoMonthsAgo =
VAR ReferenceDate = [M_StartDate2MonthsInterval]
RETURN
CALCULATE (
DISTINCTCOUNT ( 'Sales'[CustomerID] ),
'Sales'[KAM_email] = "someone@mycompany.com",
'Sales'[DateID] = ReferenceDate
)
Thanks a lot, that was it!
I do know too little about the basic mechanism in Power BI, think I'll have to attend a class. Thanks again!
Yes, because if I assign M_STartDate2MonthsInterval to a card it shows 20221130, and if I then replace <'Sales'[DateID] = [M_StartDate2MonthsInterval]> with <'Sales'[DateID] = 20221130> I get 397 customers. So there are data, but something about the use of the measure in the filter screws things up.
I tried your solution, but it didn't change anytning. And as far as I can see, the only difference is that the FILTER statement is written explicitly instead of being implisitt in the CALCULATE statement.
M_NumberOfCustomersTwoMonthsAgo is still (Blank) when using M_STartDate2MonthsInterval as value for criteria.
Are you certain that you have sales on the exact date in question ?
You can't use measures as filters because they are calculated at the aggregate level not the individual row level. To calculate at the row level you need to use an iterator to introduce a row context, so you need to use the FILTER function.
Try
M_NumberOfCustomersTwoMonthsAgo =
CALCULATE (
DISTINCTCOUNT ( 'Sales'[CustomerID] ),
FILTER (
'Sales',
'Sales'[KAM_email] = "someone@mycompany.com"
&& 'Sales'[DateID] = [M_StartDate2MonthsInterval]
)
)
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
10 | |
9 | |
8 | |
8 | |
6 |
User | Count |
---|---|
14 | |
13 | |
11 | |
9 | |
9 |