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
arlequin71
Helper II
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.

 

 

arlequin71_1-1645816241066.png

 

 

2 ACCEPTED SOLUTIONS

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.
 
Thanks in advance.

View solution in original post

v-angzheng-msft
Community Support
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.

View solution in original post

4 REPLIES 4
v-angzheng-msft
Community Support
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.

Hi, Thank you very much for your answer.

It works!.

lbendlin
Super User
Super User

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

 

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

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.
 
Thanks in 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.