cancel
Showing results for
Did you mean:
Helper II

## DAX - Count number of months by customer in a Table Visual filtered by Date

Hi, can anyone help me on this....

I need to create a metric for counting the number of months in range of Date(month) field at customer level for selected customers on selected months in the filtered table.

In the attached example the number of months is 2 for Customer 1, the Max Date is November and the min Date is October.  It would be needed to consider End of Month in max Date.

Thanks in advance for any tip.

regards.

2 ACCEPTED SOLUTIONS
Helper II

Hi, thanks for your answer but it doesn't work in my case.

I need to eliminate filter context in the table to be able to use a Dax like this example :

Count Months = Countrows(Filter(SUMMARIZE('Total Sales by Date by Dept','Total Sales by Date by Dept'[CUST_NM],'Total Sales by Date by Dept'[Date(month)],"sum months",sum('Total Sales by Date by Dept'[Total Sales])),[sum months]>0))

inside the table visual whith no inluence of other filters.

Community Support

Hi, @arlequin71

Based on the above information, to get the Month column using the following measure

``````Count Months =
CALCULATE (
DISTINCTCOUNT ( 'Total Sales by Date by Dept'[Date(month)] ),
FILTER (
ALLSELECTED ( 'Total Sales by Date by Dept' ),
'Total Sales by Date by Dept'[CUST_NM]
= MAX ( 'Total Sales by Date by Dept'[CUST_NM] )
)
)
``````

Or, please share your sample pbix file's link here, then I can try to look into it to come up with a more accurate measure.

Best Regards,
Community Support Team _ Zeon Zheng

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 REPLIES 4
Community Support

Hi, @arlequin71

Based on the above information, to get the Month column using the following measure

``````Count Months =
CALCULATE (
DISTINCTCOUNT ( 'Total Sales by Date by Dept'[Date(month)] ),
FILTER (
ALLSELECTED ( 'Total Sales by Date by Dept' ),
'Total Sales by Date by Dept'[CUST_NM]
= MAX ( 'Total Sales by Date by Dept'[CUST_NM] )
)
)
``````

Or, please share your sample pbix file's link here, then I can try to look into it to come up with a more accurate measure.

Best Regards,
Community Support Team _ Zeon Zheng

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helper II

It works!.

Super User

"It would be needed to consider End of Month in max Date"

Not really. All you need is DISTINCTCOUNT(FORMAT([date],"yyyymm"))

Helper II

Hi, thanks for your answer but it doesn't work in my case.

I need to eliminate filter context in the table to be able to use a Dax like this example :

Count Months = Countrows(Filter(SUMMARIZE('Total Sales by Date by Dept','Total Sales by Date by Dept'[CUST_NM],'Total Sales by Date by Dept'[Date(month)],"sum months",sum('Total Sales by Date by Dept'[Total Sales])),[sum months]>0))

inside the table visual whith no inluence of other filters.

Announcements