Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

Correct sales for opening times stores - DAX formula PowerBI

Hi all,

I'm pretty new to writing DAX-formulas and I'm stuck with solving the following issue. I've been searching for a long time for similar issues, but haven't found the solution that I'm looking for. Some help would be highly appreciated! Due to the sensitivity of my data I'm affraid I can't share my Powerbi file.

 

Problem: I would like to correct my monthly/yearly/etc. sales per article for the amount of days that stores have been opened. And I would like to be able to filter this for specific stores/countries or specific time periods (days, months, years, etc.). In other words, I'm looking for the (average) sales per month/.../year per store/area/country.

 

Relevant connected tables (simplified):

- Calendar

  1. Date (linked with transaction data)
  2. Year
  3. Month
  4. Week
  5. Day

- Stores

  1. Store_number (linked with transaction data)
  2. Area
  3. Country

Transaction_data (row for every single transaction)

  1. Transaction_number
  2. Article_number
  3. Turnover_incl_VAT
  4. Sales_amount
  5. Store_number (linked with stores)
  6. Transaction_date (linked with calendar)

Condition: If the total salesamount (or turnover) > 0 for a certain day & store, that specific store has been opened on that specific day.

 

What I've tried uptill now:

Sales_activestorecorrection=SUM(Transaction_data[Salesamount])/Transaction_data[Openingdays_Store]

Openingdays_Store= ????

For Openingdays_Store I think I need to use a combination including COUNTROWS(), and the condition SUM(Sales_amount)>0.

 

Any help is highly appreciated!

3 REPLIES 3
Anonymous
Not applicable

After some more testing I found out that the suggested AverageX-formula above is not the solution. 

 

Example: Let's say that 'Product A' was sold 1x in 'Store 1', 2x in 'Store 2' and 0x in 'Store 3' in January 2019. In that case, the average sales per store for Product A in January should be (1+2+0)/3=1.

 

The suggested formula above doesn't include 'Store 3' because there was no transaction in that store during January 2019. Therefore it calculates the average as (1+2)/2=1,5. In reality Product A was actually available in Store 3 and therefore Store 3 should have been included in the formula.

Anonymous
Not applicable

If you only store amounts > 0 in your Transaction_data (why would you store 0's?), then AVERAGEX on days should be enough.

[Total Sales] = SUM ( Transaction_data[Sales_amount] )

[Daily Sales Average] =
averagex(
    'Calendar',
    [Total Sales]
)


This is because averagex omits BLANKS.

 

If, however, you do have 0's, you could do this:

 

[Daily Sales Average] =
averagex(
    'Calendar',
    calculate(
        [Total Sales],
        Transaction_data[Sales_amount] <> 0
    )
)

But this will not be as fast as the one above. Storing unnecessary data in fact tables is not recommended because it leads to slower DAX and a bigger model's memory consumption. Also, the more columns you have the worse the compression rate of the table.


Best
Darek

Anonymous
Not applicable

Thanks a lot for your help @Anonymous, exactly what I have been looking for! 

 

I only got the (first) formula working once I added CALCULATE and SUM before the sales amount (see below). On the other hand, for turnover it worked only without SUM. Pretty weird, can't explain the difference, but at least my results are correct. 

 

Average sales per period =
AVERAGEX(Calendar;CALCULATE(SUM('Transaction_Data'[Sales_amount])))
 
A related question. Now that I have my average sales per period, I also tried to make a column to show the amount of days each store has been opened for that period. I guess it involves quite a similar solution, but currently still puzzeling to get it right. Maybe something with Countx instead of averagex?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.