Forum Discussion

NVG's avatar
NVG
Frequent Visitor
8 years ago

Group Data Between a Date Range

Hi all,

 

I am trying to figure out how to group sales data by the year based on what type of review it has gone through. My issue is I don't know how to account for a range of years, if the review spans more than just one year how can I assoicate the sales data with it correctly.

 

Group TypeSalesSales YearReview Start DateReview End DateReview Type
12014500020142016A
22015600020102013B
32016700020142017C
42015800020142016A
52016900020152016A

 

In this example I would expect the following results for the time period 2014-2017 which I have set with a splicer.

Total Sales35000
Review Type A22000
Review Type B0
Review Type C7000
Not Reviewed6000

 

Here the total sales is just the sum of the sales which they all fall betwen 2014 and 2017. Then you have sales for Review Type A that fall on the first review date, inbetween, and the final year. Review Type B has no sales becuase the review took place in a time frame prior to the sales year.

 

I would like to be able to group by Group Type and have totals for each Review Type as my final results as the Group Types will repeat in the full data set.  In the full data you would end up with Group Type 1-xxx and the following for each Group Type: Total Sales, Total for Review A, B, C and Total Not Reviewed.

 

Thank you for the help! 

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    You can use the following DAX to get a new table group by Review Type. Then you can use it to get the similar information as you expected. I did not find a way that could merge Not Reviewed information in to Review Type table. Maybe someone else could help.

     

    ReviewSummary = GROUPBY(Review,Review[Review Type],"SalesSum",SUMX(CURRENTGROUP(),IF(Review[Review End Date]>=Review[Sales],Review[Sales Year],0)))

     

     

     

    • NVG's avatar
      NVG
      Frequent Visitor

      Thank you for the formula. I was able to replicate it for my data. I think I wasn't very clear on needing the Group Type as well, I didn't put it in my example solution like I should have.

       

      I would like to also include the Group Type. In a perfect world the solution would look like the following:

       

      For 2014-2017     
      Group TypeTotal SalesReview Type AReview Type BReview Type CNot Reviewed
      150005000000
      260000006000
      370000070000
      480008000000
      590009000000

       

      I can also just caculate the Not Reviewed column by doing a subtraction of Total Sales - All Review Types but I wasn't sure how to get table created in this format for a larger data set.

       

      Thanks!