Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

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
 
 

 

  • Anonymous , 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]
                )
            )
        )

4 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    Perhaps:

     

    Column = COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER('T',[MemberID] = EARLIER([MemberID])),"SupplierID",[SupplierID])))
    • Anonymous's avatar
      Anonymous
      Not applicable

      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 

      • Greg_Deckler's avatar
        Greg_Deckler
        Icon for Community Champion rankCommunity Champion

        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.