Forum Discussion

YasminYas's avatar
YasminYas
Helper I
7 years ago
Solved

User selected date fetch dynamic values in visual

Hi , I have written view which fetch activity details of each user , Columns include ID, Activitydate, Name and other. So My requirements is If user selects any date from date slicer then my table visual should show id,name, Last 30 days , Last 90 days like that. So I have created a date table which has dates from 2017-01-01(Since date activity date starts from 2017-01-01) to today's date . Fuctinality should be : 1.User selected date > Activitydate of user , Then user selected date should be deducted by all activity dates of each user and the result we get in days. 2. If the day is <=30, then it should show 1 in that Last 30 days calculated column(Since i need to create card visual for count of Last 30 days for each user)that is why iam mentioning calclulated columns. Note : So I have created a date table which has dates from 2017-01-01(Since date activity date starts from 2017-01-01) to today's date . and created a measure 1.User selected date = calculate(SELECTEDVALUE('Date'[Date]),ALLEXCEPT('Date','Date'[Date])) 2.I have created another measure for Daycount selectActivityDate = calculate(SELECTEDVALUE(vw_MemberactivityonUserdate[activitydate]),ALLEXCEPT('vw_MemberactivityonUserdate','vw_MemberactivityonUserdate'[activitydate])) Daycount = IF([selectMeasure]>[selectActivityDate],DATEDIFF([selectMeasure],[selectLAD],DAY)*-1,"Novalue") 3.Last30 = if([Daycount]>0 &&; [Daycount]<=30,1,blank()) 4.Last90 = if([Daycount]>30[Daycount]<=90,1,blank()) I have created all these measures. But in table visual iam getting all the activitydates of each user (If user has 10 activity dates iam gettiing 10 rows), End result should be : 1.I need to show table visual which get only one row for each user with ID, Name, lastactivitydate(means max of lastactivity), Last 30 days, Last 90 days 2.I need to shoe card visual which shows count of id for Last 30 days based on user selected date as well as for Last 90 days
  • Hi YasminYas,

     

    I made one sample for your reference. Please check the following steps as below.

     

    1. To create two measures as below and make the tables visuals filtlerd by them as the picture.

     

    last30T = var seledate = SELECTEDVALUE('date'[Date])
    return
    IF(MAX(Table1[Activitydate])>seledate-30 && MAX(Table1[Activitydate])<=seledate,1,BLANK())
    last90T = var seledate = SELECTEDVALUE('date'[Date])
    return
    IF(MAX(Table1[Activitydate])>seledate-90 && MAX(Table1[Activitydate])<=seledate,1,BLANK())

     

    2. To create another two measures.

     

    last30days = var seledate = SELECTEDVALUE('date'[Date])
    return
    CALCULATE(COUNTROWS(Table1),FILTER(Table1,Table1[Activitydate]>seledate-30 && Table1[Activitydate]<=seledate))
    last90days = var seledate = SELECTEDVALUE('date'[Date])
    return
    CALCULATE(COUNTROWS(Table1),FILTER(Table1,Table1[Activitydate]>seledate-90 && Table1[Activitydate]<=seledate))

    For more details, please check the pbix as attached.

     

    Regards,

    Frank

  • YasminYas's avatar
    YasminYas
    7 years ago

    Hi Frank,
    Thanks for your reply.
    But I am not getting correct resluts.
    Here is my data , When I am checking for Haman by filtering Today's date Result is ilke 1 for all 30,90,180,365
    But User has only 03/01/2019 and 14/01/2019 so when Iam checking for Today's date I shoud get 1 in Last 30 only.

    Measure used 

    Last30T =
    VAR SELECTDATE = SELECTEDVALUE('Date'[Date])
    RETURN
    IF(MAX(vw_MemberactivityonUserdate[Lastactivitydate])>SELECTDATE-30 && MAX(vw_MemberactivityonUserdate[Lastactivitydate])<=SELECTDATE,1,BLANK())
    and card visual should show 1 for Last 30 But it is showing 2
    LAST30Days =
    var selectdate = SELECTEDVALUE('Date'[Date])
    return
    CALCULATE(COUNTROWS(vw_MemberactivityonUserdate),FILTER(vw_MemberactivityonUserdate,vw_MemberactivityonUserdate[Lastactivitydate]>selectdate-30 && vw_MemberactivityonUserdate[Lastactivitydate]<=selectdate))


    https://www.dropbox.com/s/hgu8omr0af6w157/Test_Jan16.pbix?dl=0

     

    Thanks in advance 

  • Hi YasminYas,

     

    We got the result as 2 coz we are using COUNTROWS here. Then we can update the formula as below. 

     

    last90days = var seledate = SELECTEDVALUE('date'[Date])
    return
    CALCULATE(DISTINCTCOUNT(Data[ScreenName]),FILTER(Data,Data[Activitydate]>seledate-90 && Data[Activitydate]<=seledate))

     

     

    Regards,

    Frank

3 Replies

  • v-frfei-msft's avatar
    v-frfei-msft
    Community Support

    Hi YasminYas,

     

    I made one sample for your reference. Please check the following steps as below.

     

    1. To create two measures as below and make the tables visuals filtlerd by them as the picture.

     

    last30T = var seledate = SELECTEDVALUE('date'[Date])
    return
    IF(MAX(Table1[Activitydate])>seledate-30 && MAX(Table1[Activitydate])<=seledate,1,BLANK())
    last90T = var seledate = SELECTEDVALUE('date'[Date])
    return
    IF(MAX(Table1[Activitydate])>seledate-90 && MAX(Table1[Activitydate])<=seledate,1,BLANK())

     

    2. To create another two measures.

     

    last30days = var seledate = SELECTEDVALUE('date'[Date])
    return
    CALCULATE(COUNTROWS(Table1),FILTER(Table1,Table1[Activitydate]>seledate-30 && Table1[Activitydate]<=seledate))
    last90days = var seledate = SELECTEDVALUE('date'[Date])
    return
    CALCULATE(COUNTROWS(Table1),FILTER(Table1,Table1[Activitydate]>seledate-90 && Table1[Activitydate]<=seledate))

    For more details, please check the pbix as attached.

     

    Regards,

    Frank

    • YasminYas's avatar
      YasminYas
      Helper I

      Hi Frank,
      Thanks for your reply.
      But I am not getting correct resluts.
      Here is my data , When I am checking for Haman by filtering Today's date Result is ilke 1 for all 30,90,180,365
      But User has only 03/01/2019 and 14/01/2019 so when Iam checking for Today's date I shoud get 1 in Last 30 only.

      Measure used 

      Last30T =
      VAR SELECTDATE = SELECTEDVALUE('Date'[Date])
      RETURN
      IF(MAX(vw_MemberactivityonUserdate[Lastactivitydate])>SELECTDATE-30 && MAX(vw_MemberactivityonUserdate[Lastactivitydate])<=SELECTDATE,1,BLANK())
      and card visual should show 1 for Last 30 But it is showing 2
      LAST30Days =
      var selectdate = SELECTEDVALUE('Date'[Date])
      return
      CALCULATE(COUNTROWS(vw_MemberactivityonUserdate),FILTER(vw_MemberactivityonUserdate,vw_MemberactivityonUserdate[Lastactivitydate]>selectdate-30 && vw_MemberactivityonUserdate[Lastactivitydate]<=selectdate))


      https://www.dropbox.com/s/hgu8omr0af6w157/Test_Jan16.pbix?dl=0

       

      Thanks in advance 

      • v-frfei-msft's avatar
        v-frfei-msft
        Community Support

        Hi YasminYas,

         

        We got the result as 2 coz we are using COUNTROWS here. Then we can update the formula as below. 

         

        last90days = var seledate = SELECTEDVALUE('date'[Date])
        return
        CALCULATE(DISTINCTCOUNT(Data[ScreenName]),FILTER(Data,Data[Activitydate]>seledate-90 && Data[Activitydate]<=seledate))

         

         

        Regards,

        Frank