Forum Discussion

KarlNixon's avatar
KarlNixon
Icon for Advocate I rankAdvocate I
7 years ago
Solved

Date formula All values to a max date?

Is there a function to calculate all values up to a filtered date?

 

Something like 

 

Total Qty quoted alltime = CALCULATE (
SUMX (quotation_data_tab,[Qty] ),
FILTER (
ALL ( quotation_data_tab[bi_sd_so_order_date]),
quotation_data_tab[bi_sd_so_order_date]<= MAX (quotation_data_tab[bi_sd_so_order_date])
)
)
 
 
 
But where the date filter applied only applies to the maximum date and includes all lesser dates.
 
If I apply a filter to the view (ie March 2018) I only get the result for that selection, not all prior date values?
 
 
Help appreciated :smileywink:
  • v-frfei-msft's avatar
    v-frfei-msft
    7 years ago

    Hi KarlNixon,

     

    If there is relationship between data table and the fact tabel, once you choose any value in the slicer. Then the fact table will be filterd accrodingly. Then you cannot get the result as you want in the table visual. However for the value in the card, we can use ALL function to ignore the filer. So we can update the measure as below to work on it.

     

    Measure 2 = CALCULATE(SUM(Table1[qty]),FILTER(ALL(Table1),Table1[date]<=MAX('CALENDAR'[Date])))

    For more detaills, please check the pbix as attacched.

     

    Regards,

    Frank

5 Replies

  • v-frfei-msft's avatar
    v-frfei-msft
    Icon for Community Support rankCommunity Support

    Hi KarlNixon,

     

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

     

    1. Create a CALENDAR table and create a calculated column in it.

     

    CALENDAR = CALENDARAUTO()
    Yearmonth = FORMAT('CALENDAR'[Date],"yyyymmm")

    2. Create the measures as below.

     

    Measure = var maxdt = MAX('Table1'[date])
    var maxdc = MAX('CALENDAR'[Date])
    return 
    IF(maxdc>=maxdt,1,0)
    
    Measure 2 = CALCULATE(SUM(Table1[qty]),FILTER(Table1,Table1[date]<=MAX('CALENDAR'[Date])))

    Please filter the table visual by the measure as the picture as below. 

     

    For more details, please check the pbix as attached.

     

    Regards,

    Frank

     

    • KarlNixon's avatar
      KarlNixon
      Icon for Advocate I rankAdvocate I

      Hi Frank,

       

      It looks like the solution won't work if there is a relationship between the Table1[Date] field and the Calander[Date] field

       

      I'm perplexed as to why?

       

       

      Karl

    • v-frfei-msft's avatar
      v-frfei-msft
      Icon for Community Support rankCommunity Support

      Hi KarlNixon,

       

      If there is relationship between data table and the fact tabel, once you choose any value in the slicer. Then the fact table will be filterd accrodingly. Then you cannot get the result as you want in the table visual. However for the value in the card, we can use ALL function to ignore the filer. So we can update the measure as below to work on it.

       

      Measure 2 = CALCULATE(SUM(Table1[qty]),FILTER(ALL(Table1),Table1[date]<=MAX('CALENDAR'[Date])))

      For more detaills, please check the pbix as attacched.

       

      Regards,

      Frank

      • KarlNixon's avatar
        KarlNixon
        Icon for Advocate I rankAdvocate I

        Thanks for your help Frank - all solved!

         

         

         

         

  • Hi,

     

    Ensure you have a Calendar Table with a relationship from the Date column of the quotation_data_tab Table to the Date column of the Calendar Table.  Drag the Dates from the Calendar Table to the slicer.  Write this measure

     

    =CALCULATE([Qty],DATESBETWEEN(Calendar[Date],MINX(ALL(Calendar),Calendar[Date]),MAX(Calendar[Date]))

     

    Hope this helps.