Forum Discussion
Date Hierarchy with Filtered Summarize DAX function not as expected
Hi you all,
I'm hoping you can help me out on something. I've created a dax measure which gives me a distinct count of a contact column on two filters, one which is a column filter value (contribution status) , another is the count of a column of a summarize function (the contact should have at least 2 contribution_bk).
Ideally I want to have a rolling 12 month view of this measure with a year-quarter hierarchy The expected behaviour and results should be :
- The value on 2023-Q4 should show me the distinct count of a column with the set filters for the last 12 months , so from 01-01-2023 to 31-12-2023
- 2023-Q3 should show me the distinct count of a column with the set filters for the last 12 months , so from 01-10-2023 to 30-09-2023
The dax measure:
in the star model, the fct_contribution has a relationship with the dim_calendar table.
- Anonymous2 years ago
Hi mike_sjief ,
Consider creating a separate metric to calculate rolling 12-month totals rather than using it directly in an existing metric.
Try modifying the following formula:Rolling12M_CountOfDistinctContacts = CALCULATE ( [CountOfDistinctContacts], FILTER ( ALLSELECTED ( dim_calendar ), dim_calendar[d_date] IN DATESINPERIOD ( dim_calendar[d_date], MAX ( dim_calendar[d_date] ), -12, MONTH ) ) )Best Regards,
Adamk KongIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly
2 Replies
- AnonymousNot applicable
Hi mike_sjief ,
Consider creating a separate metric to calculate rolling 12-month totals rather than using it directly in an existing metric.
Try modifying the following formula:Rolling12M_CountOfDistinctContacts = CALCULATE ( [CountOfDistinctContacts], FILTER ( ALLSELECTED ( dim_calendar ), dim_calendar[d_date] IN DATESINPERIOD ( dim_calendar[d_date], MAX ( dim_calendar[d_date] ), -12, MONTH ) ) )Best Regards,
Adamk KongIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- mike_sjiefNew Member
Hi Adamk,
this is indeed what I tried just after I posted it. It worked. Your dax is a bit more elegant so I greatly appreciate your reply.
Kind regards,
Mike