cancel
Showing results for 
Search instead for 
Did you mean: 
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
August 2022 update 768x460.jpg

Check it Out!

Click here to learn more about the August 2022 updates!

August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors