Forum Discussion

Kaskazi_Network's avatar
5 years ago
Solved

Distinct Values with date filter

Hi,

I would like some help in displaying distinct values for a specified period of time. 'DISTINCT COUNT' works seamlessly without a filter applied. For example let's say I would like to see distinct shops visited in week 35, I should be able to see ShopE only since ShopB and ShopD have been visited in week 29 and week 34 respectively.

Any advice how this can achieved?

Shop_idShop_nameDate_VisitedWeek_No
100ShopA14/7/2029
101ShopB15/7/2029
102ShopC22/7/2030
103ShopD17/8/2034
100ShopA21/8/2034
102ShopC13/8/2033
106ShopE29/8/2035
101ShopB23/8/2035
103ShopD25/8/2035
101ShopB14/9/2038
  • @Kaskazi_Network

    Here is an alternative (table name 'ShopVisits'):
    1) Measure to use in the filter panel to filter a table

    Distinct visits = 
    VAR PrevVisit = CALCULATETABLE(VALUES(ShopVisits[Shop_name]), 
                    FILTER(ALL(ShopVisits[Week_No]), 
                    ShopVisits[Week_No] < SELECTEDVALUE(ShopVisits[Week_No])))
    VAR Selected = VALUES(ShopVisits[Shop_name])
    RETURN
    COUNTROWS(EXCEPT(Selected, PrevVisit))

    2) measure to list the new stores visited:

    New Shops visited = CONCATENATEX(FILTER(ALL(ShopVisits[Shop_name]), 
                        [Distinct visits] = 1), 
                        ShopVisits[Shop_name], ", ")

    And you understand this:

    Result.JPG

4 Replies

  • Kaskazi_Network , Try a measure like

    Assume a week is selected

     

    countx(values(Shop_id) , if(distinctcount(Table[Week_No]) ,calculate(distinctcount(Table[Week_No]) , filter(all(Table), Table[Week_No]<=selectedvalue(Table[Week_No])))<=0, blank(),1))

     

    Best is that you move week to week table

    and try like

    countx(values(Shop_id) , if(distinctcount(Table[Week_No]) ,calculate(distinctcount(Table[Week_No]) , filter(all(Week), Week[Week_No]<=selectedvalue(Week[Week_No])))<=0, blank(),1))

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Kaskazi_Network Maybe something like the following?

    Measure = 
      VAR __Min = MIN('Table'[Date])
      VAR __Max = MAX('Table'[Date])
    RETURN
      COUNTROWS(DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table')[Date_Visited]>=__Min && [Date_Visited]>=__Max),"Shop_name",[Shop_name])))
  • PaulDBrown's avatar
    PaulDBrown
    Community Champion

    @Kaskazi_Network

    Here is an alternative (table name 'ShopVisits'):
    1) Measure to use in the filter panel to filter a table

    Distinct visits = 
    VAR PrevVisit = CALCULATETABLE(VALUES(ShopVisits[Shop_name]), 
                    FILTER(ALL(ShopVisits[Week_No]), 
                    ShopVisits[Week_No] < SELECTEDVALUE(ShopVisits[Week_No])))
    VAR Selected = VALUES(ShopVisits[Shop_name])
    RETURN
    COUNTROWS(EXCEPT(Selected, PrevVisit))

    2) measure to list the new stores visited:

    New Shops visited = CONCATENATEX(FILTER(ALL(ShopVisits[Shop_name]), 
                        [Distinct visits] = 1), 
                        ShopVisits[Shop_name], ", ")

    And you understand this:

    Result.JPG