Forum Discussion

ronenbitman's avatar
ronenbitman
Frequent Visitor
9 years ago

Slicer & CalcilatedColumn

Hi,


i have a report with a Slicer "As of Date" the is linked to the DateDimension, all works great,

i need to add a Histogram for Age of the Customer Facts,

as such i added a calculated column in the Customer Facts table that would show the customerAge as of ReportDate,



DATEDIFF(DateOfBirth,  'Date Dimension'[Date])


now i would assumed that if i would change the slicer to a different date the histogram would change, but no it remains static, but all the rest of the report changed according to the selected date correctly

i do not have a relationship between the dateDimension & the customer (do i need one? wouldn't it filter the customer rows by the selected date?)


where am i wrong?

8 Replies

  • Baskar's avatar
    Baskar
    Resident Rockstar

    For my understanding do u want get the age based on slicer selction date ?

     

    If yes your aproach is wrong . the reason is if u create calculated column it is static it won't change while slicer change.

     

    u have to create calculated Measure instead of Calculated Column.

     

    Share ur column and sample data i will help u.

     

    The idea is create new measure :

    Get DOB in Var , like Var DOB = Max(DateOfBirth)

    Get Max Date on Slicer   like Var Max_Date = Max('Date Dimension'[Date]).

     

    then final Datediff : Return Datediff(DOB,Max_Date,DAY).

     

    Note: 

    If ur DOB is greater then slicer it will give u the error.

     

    So add one condition in final return : 

     

    Return if ( Max_Date < DOB, Blank(), Datediff(DOB,Max_Date,DAY))

     

    Let me know , any help

    • ronenbitman's avatar
      ronenbitman
      Frequent Visitor

      Hi Baskar,

       

      thanks for the answer

       

      my initial question was not the actual one as i tried to make the explanation of my schema easier, but i understand the idea behind what you are saying, however i still unable to see how to accomplish this,
      i am not able to attach the data but i attached the Schema an (hopefully) added the information that is evolved in my requirement.

      basicly i have two requirements

      - show the count of not accredited Investor, so i added the measure

      Not Accredited Investor Count = COUNTX(Filter('Investor Facts','Investor Facts'[Accredited Month Age]<>0),'Investor Facts'[Accredited Month Age] )

      Facts'[Accredited Month Age] )]

      - show a histogram of Accredited Month Age - so i added a calculated column

       

      Accredited Month Age = 
      	VAR InternalSelectedDate = 'Date Dimension'[SelectedDate]
      	VAR In12Month = EOMONTH([Latest Subscription Activity],12)
          VAR EndOfAccreditedPeriod = 
              IF(
                  DAY([Latest Subscription Activity])>DAY(In12Month),
                          DATE(year(In12Month),month(In12Month),day(In12Month)),
                          DATE(year(In12Month),month(In12Month),day([Latest Subscription Activity]))
              )
          RETURN
              if(
                  'Investor Facts'[Investor Accreditied Class]="A" || 'Investor Facts'[Investor Accreditied Class]="B" || 'Investor Facts'[Investment Type]="Provident Fund"
                  , 0
                  , if(EndOfAccreditedPeriod > NOW(), DATEDIFF(InternalSelectedDate,EndOfAccreditedPeriod,MONTH), 0)
              )

       

      i added a workaround as the DateDiff is unable to add dates that are not defined in the 'Date Dimension' Table

       

      could you please try to point me to the right way to implement this

       

       

       

       

      many thanks for the help

       

       

       

      • v-huizhn-msft's avatar
        v-huizhn-msft
        Microsoft Employee

        Hi ronenbitman,

        >>i added a workaround as the DateDiff is unable to add dates that are not defined in the 'Date Dimension' Table

         

        Based on my understanding, using the DateDiff function in "Accredited Month Age" measure returns an error or something else? Could you please post 'Investor Facts' table for further analysis? If your data is private, you can create sample data in similar format.

         

        Best Regards,
        Angelia