cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

Need help in DAX, Distinct Count

Hi, I am trying to calculate distinct count for Supplier ID based on Member ID, but it's not working the I want, please find DAX below

DistinctSupplierID =
var __member = T[MemberID]
var __endDate = T[ReportReceived].[Date]
var __startDate = EDATE( __endDate, -6)
var __result =
CALCULATE(
    DISTINCTCOUNT(T[SupplierID]),
        SELECTCOLUMNS(
            FILTER(
                T,
                T[MemberID] = __member
// __startDate <= T[ReportReceived].[Date]
            ),
"SuppID", T[SupplierID]
    )
)
return
    __result
 
Data:
SupplierIDMemberIDReportReceivedDistinctSupplierIDedate
319131-03-2005 00:00230-09-2004 00:00
278131-03-2005 00:00230-09-2004 00:00
214109-08-2005 00:00109-02-2005 00:00
99127-01-2006 00:00127-07-2005 00:00
446121-02-2006 00:00121-08-2005 00:00
446121-02-2006 00:00121-08-2005 00:00
446113-09-2005 00:00113-03-2005 00:00
147130-04-2005 00:00130-10-2004 00:00
112216-12-2005 00:00216-06-2005 00:00
111216-12-2005 00:00216-06-2005 00:00
111216-01-2006 00:00116-07-2005 00:00
111217-02-2006 00:00117-08-2005 00:00
111219-10-2005 00:00119-04-2005 00:00
111224-08-2005 00:00124-02-2005 00:00
111206-07-2005 00:00106-01-2005 00:00
178230-07-2005 00:00130-01-2005 00:00
187207-01-2005 00:00107-07-2004 00:00
109207-11-2005 00:00107-05-2005 00:00
187226-07-2005 00:00126-01-2005 00:00
 
 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User IV
Super User IV

Re: Need help in DAX, Distinct Count

@amolNv2 , OK, you want this:

 

Column = 
var __endDate = T[ReportReceived].[Date]
var __startDate = EDATE( __endDate, -6)
RETURN
    COUNTROWS(
        DISTINCT(
            SELECTCOLUMNS(
                FILTER(
                    'T',
                    [MemberID] = EARLIER([MemberID]) &&
                        T[ReportReceived].[Date] <= __endDate &&
                            T[ReportReceived].[Date] >= __startDate
                ),
                "SupplierID",[SupplierID]
            )
        )
    )

---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
Highlighted
Super User IV
Super User IV

Re: Need help in DAX, Distinct Count

Perhaps:

 

Column = COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER('T',[MemberID] = EARLIER([MemberID])),"SupplierID",[SupplierID])))

---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted
Frequent Visitor

Re: Need help in DAX, Distinct Count

The result is 6. I am not expecting this. I want from ant date to last 6 months how many unique Supplier Id. 

For above data the distinct supplier Id column should be 

2,2,4,3,2,2,5,3,5,5,5,3,3,3,2,3,1,4,2

@Greg_Deckler 

Highlighted
Super User IV
Super User IV

Re: Need help in DAX, Distinct Count

Oh, you commented out that line in your code so I thought you didn't want it. It is hard for me to test exactly because I'm in the US so your dates don't convert so well, let me see what I can do about that.


---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Highlighted
Super User IV
Super User IV

Re: Need help in DAX, Distinct Count

@amolNv2 , OK, you want this:

 

Column = 
var __endDate = T[ReportReceived].[Date]
var __startDate = EDATE( __endDate, -6)
RETURN
    COUNTROWS(
        DISTINCT(
            SELECTCOLUMNS(
                FILTER(
                    'T',
                    [MemberID] = EARLIER([MemberID]) &&
                        T[ReportReceived].[Date] <= __endDate &&
                            T[ReportReceived].[Date] >= __startDate
                ),
                "SupplierID",[SupplierID]
            )
        )
    )

---------------------------------------

Putting square pegs in round holes since 1972.

I have a NEW book! 
DAX Cookbook from Packt
Over 120 DAX Recipes!




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

Helpful resources

Announcements
August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Upcoming Events

Upcoming Events

Wondering what events you could join or have an event to promote yourself? Check out our Upcoming Events.

Community Summit Australia – Join Online!

Community Summit Australia – Join Online!

Be a part of the leading Microsoft Business Applications digital event, curated for the APAC community.