Forum Discussion

jyaul786's avatar
jyaul786
Helper II
3 years ago
Solved

Sum on two different date range

Dear Friend

 

i have columns : date,sales amount.  

 

 

i want to display sum of amount( in card or line chart) in two different date range as shown below:

how can i achieve this using dax

 

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi jyaul786 ,

     

    According to your description, here are my steps you can follow as a solution.

    (1)  My test data is the same as yours.

    (2) We can create two tables.

    Slicer1 = CALENDAR(DATE(2021,1,1),DATE(2022,12,31)) 
    Slicer2 = CALENDAR(DATE(2021,1,1),DATE(2022,12,31)) 

    (3)We can create a measure. 

    sum = 
    var _1_start=FIRSTDATE('Slicer1'[Date])
    var _1_end=LASTDATE('Slicer1'[Date])
    var _2_start=FIRSTDATE('Slicer2'[Date])
    var _2_end=LASTDATE('Slicer2'[Date])
    var _1_sales=
    CALCULATE(SUM('Table'[sales amount]),FILTER(ALL('Table'),'Table'[date]>=_1_start && 'Table'[date]<=_1_end))
    var _2_sales=
    CALCULATE(SUM('Table'[sales amount]),FILTER(ALL('Table'),'Table'[date]>=_2_start && 'Table'[date]<=_2_end))
    return _1_sales+_2_sales

    (3) Then the result is as follows.

     

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi jyaul786 ,

     

    According to your description, here are my steps you can follow as a solution.

    (1)  My test data is the same as yours.

    (2) We can create two tables.

    Slicer1 = CALENDAR(DATE(2021,1,1),DATE(2022,12,31)) 
    Slicer2 = CALENDAR(DATE(2021,1,1),DATE(2022,12,31)) 

    (3)We can create a measure. 

    sum = 
    var _1_start=FIRSTDATE('Slicer1'[Date])
    var _1_end=LASTDATE('Slicer1'[Date])
    var _2_start=FIRSTDATE('Slicer2'[Date])
    var _2_end=LASTDATE('Slicer2'[Date])
    var _1_sales=
    CALCULATE(SUM('Table'[sales amount]),FILTER(ALL('Table'),'Table'[date]>=_1_start && 'Table'[date]<=_1_end))
    var _2_sales=
    CALCULATE(SUM('Table'[sales amount]),FILTER(ALL('Table'),'Table'[date]>=_2_start && 'Table'[date]<=_2_end))
    return _1_sales+_2_sales

    (3) Then the result is as follows.

     

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

    If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly.