Forum Discussion

rexeubank's avatar
rexeubank
Frequent Visitor
6 years ago
Solved

Sales Data Pre/Post a Specific Date

Hello,

 

I'm having trouble with a calculated column. I am trying to see sales data 3 weeks prior and post-visitation to a store so I can compare with the week that the store is visited.

 

I have the formula in a calculated column below, which matches the sales data store number & week number to that of the store visitation export (I just add a +1 or -1 to change the week number for pre- and post-visitation weeks).

Current Week =
SUMX(
FILTER(
'Sales',
AND(
'Sales'[Week Number] = 'Combined Recaps'[WM Week],
'Sales'[Store Number] = 'Combined Recaps'[Retail ID]
)
),
'Sales'[Sales]
)
 
The columns work just fine, the issue comes when I'm trying to filter the sales data by brand or type of sale. I believe I need to put this formula into a measure somehow, but I can't figure out a formula that works.
 
Any help is much appreciated! Thank you.
  • Hi rexeubank 

     

    The claculated column can't be changed by the other table's filter. I believe you can achieve this by changing it to the measure as below:

    Measure = SUMX(
            FILTER(
                ALLSELECTED('Sales'),
                AND(
                    'Sales'[Week Number] = MAX('Combined Recaps'[WM Week]),
                    'Sales'[Store Number] = MAX('Combined Recaps'[Retail ID])
                )
            ),
            'Sales'[Sales]
        )

4 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Icon for Community Champion rankCommunity Champion

    rexeubank - Yeah, you need to use an aggregator around your column references in a measure. Hard to be more specific, Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

    Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

    The most important parts are:
    1. Sample data as text, use the table tool in the editing bar
    2. Expected output from sample data
    3. Explanation in words of how to get from 1. to 2.

    • rexeubank's avatar
      rexeubank
      Frequent Visitor

      I apologize for the vagueness. Maybe this can help:

       

      Below is my data.

      On the top, I have the visitation export (what stores were visited and when). This is where the calculated columns are located.

      On the bottom is the sales data. I match the week numbers and the store numbers (Retail ID/Store Number) and sum the sales data based on those two criteria.

      And the calculated column code for easier viewing.

      I need to get the weekly sales into a format where I can filter them by the Brand & Type from the Sales tab.

       

      Current Week =
         SUMX(
              FILTER(
                  'Sales',
                  AND(
                      'Sales'[Week Number] = 'Combined Recaps'[WM Week],
                      'Sales'[Store Number] = 'Combined Recaps'[Retail ID]
                  )
              ),
              'Sales'[Sales]
          )

       

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

        Hi rexeubank 

         

        The claculated column can't be changed by the other table's filter. I believe you can achieve this by changing it to the measure as below:

        Measure = SUMX(
                FILTER(
                    ALLSELECTED('Sales'),
                    AND(
                        'Sales'[Week Number] = MAX('Combined Recaps'[WM Week]),
                        'Sales'[Store Number] = MAX('Combined Recaps'[Retail ID])
                    )
                ),
                'Sales'[Sales]
            )

  • rexeubank , refer my post on week can help you

     

    https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
    https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123

    example

    Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)	
    This Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
    Last Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))
    Last year Week= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=(max('Date'[Week Rank]) -52)))